覆盖

为了

For

伊娜、雷切尔和亚伦

Ina, Rachel and Aaron

原始数据

Original data

原始版版权所有 © 2013 Cengage Learning。版权所有。英文原文标题:计算理论导论。第三版,作者:Michael Sipser。波兰语版版权所有 2020,波兰科学出版社 PWN Wydawnictwo Naukowe PWN Spółka Akcyjna。版权所有。

Original edition copyright © 2013 by Cengage Learning. All rights reserved. Title of English-language original: Introduction to the theory of computation. Third edition by Michael Sipser. Polish edition copyright 2020 by Polish Scientific Publishers PWN Wydawnictwo Naukowe PWN Spółka Akcyjna. All rights reserved.

由 Marek Włodarz代表WITKOM翻译,Witold Sikorski

Translation by Marek Włodarz on behalf of WITKOM Witold Sikorski

波兰语版的封面设计由 Joanna Andryjowicz设计

Cover design of the Polish edition by Joanna Andryjowicz

发行商: Wioleta Szczygielska-Dybciak

Publisher Wioleta Szczygielska-Dybciak

总编辑乔兰塔·科瓦尔丘克

Managing Editor Jolanta Kowalczuk

编辑Piotr Faliszewski

Editor Piotr Faliszewski

校对:Jolanta Kucharska

Proofread by Jolanta Kucharska

制作协调员Anna Bączkowska

Production coordinator Anna Bączkowska

实质性咨询

Content consultation

博士工程师彼得·法利谢夫斯基,副教授

Dr. Habil. Eng. Piotr Faliszewski , Associate Professor

AGH科技大学斯坦尼斯瓦夫·斯塔齐奇在克拉科夫

AGH University of Science and Technology named after Stanisław Staszic in Kraków

本书中使用的注册公司和产品名称仅用于识别目的。

Proprietary company and product names used in this book are for identification purposes only.

 

 

 

 

 

 

委托PWN科学出版社编写电子版

Electronic version composition commissioned by PWN Scientific Publishing House

莫妮卡·利皮克 / Woblink

Monika Lipiec / Woblink

您购买的图书是作者和出版商的作品。我们请求您尊重他们的权利。您可以与您亲近的人或您认识的人免费分享其内容。但不要将其发布到互联网上。如果您引用其中的片段,请勿更改其内容,并务必注明是谁的作品。如果您复制其中的一部分,请仅用于个人用途。

The book you have purchased is the work of the creator and publisher. Please respect the rights they have. You can share its content free of charge with people close to you or known to you personally. But do not publish it on the Internet. If you quote fragments of it, do not change their content and be sure to indicate whose work it is. And if you copy part of it, do it only for personal use.

让我们尊重他人的财产和权利

Let's respect other people's property and rights

更多信息请访问www.legalnakultura.pl

More at www.legalnakultura.pl

波兰书商会

Polish Chamber of Books

 

 

 

 

波兰语版版权所有 © Wydawnictwo Naukowe PWN SA

Copyright © for the Polish edition by PWN SA Scientific Publishing House

2020 年华沙

Warsaw 2020

ISBN 978-83-01-21099-1

ISBN 978-83-01-21099-1

该电子书是在 2020 年纸质版的基础上编写的(WN PWN 第 3 版 - 第 1 版)

The eBook was prepared based on the 2020 paper edition (3rd - 1st edition in WN PWN)

2020 年华沙

Warsaw 2020

科学出版社 PWN SA

PWN SA Scientific Publishing House

02-460 华沙,ul。戈特利布·戴姆勒 2

02-460 Warsaw, Gottlieb Daimlera 2

电话:22 69 54 321,传真:22 69 54 288

tel. 22 69 54 321, fax 22 69 54 288

热线电话 801 33 33 88

hotline 801 33 33 88

电子邮件:pwn@pwn.com.plreklama@pwn.pl

e-mail: pwn@pwn.com.pl ; reklama@pwn.pl

www.pwn.pl

www.pwn.pl

内容

Contents

第一部分:自动化和语言

PART I. AUTOMATES AND LANGUAGES

第二部分相容性理论

PART II. THEORY OF OBLIGATION

第三部分。复杂性理论

PART III. COMPLEXITY THEORY

第一版前言

Preface to the First Edition

致学生们

To students

你好!

Hello!

您即将开始学习一个令人着迷且重要的领域:计算理论。它涵盖了计算机硬件、软件及其某些应用的基本数学特性。当我们研究这个领域时,我们试图确定什么可以计算,什么不能计算,可以多快完成,需要多少内存,以及采用什么类型的计算模型。这些问题显然与工程实践相关,同时,与许多科学领域一样,它们也具有纯粹的哲学方面。

You are about to begin exploring a fascinating and important field: computational theory. It encompasses the fundamental mathematical properties of computer hardware, software, and some of their applications. In studying this field, we try to determine what can and cannot be computed, how fast it can be done, how much memory is needed, and in what kind of computational model. These issues are obviously related to engineering practice, and at the same time, as in many fields of science, they also have purely philosophical aspects.

我知道你们中的许多人都期待着学习这些材料,尽管也许并非所有人都愿意来到这里。也许您想获得计算机科学或工程学文凭,并且理论讲座就在必需的清单上 - 只有上帝知道为什么。难道理论不是模糊的、无聊的,更糟糕​​的是,无关紧要的吗?

I know that many of you are eager to learn this material, although perhaps not all of you are here willingly. Perhaps you are looking to get a degree in computer science or engineering, and a theory course is on the required list—God knows why. Isn't theory muddy, boring, and worse, irrelevant?

继续读下去,你会发现这个理论既不晦涩难懂,也不乏味,而是很容易理解,甚至很有趣。理论计算机科学包含许多精彩的大想法,但也有一些小而有时无聊的细节,可能会令人厌倦。学习新事物总是很困难,但如果材料呈现得当,它会变得更容易、更有趣。我写这本书的主要目标是向读者展示计算理论的迷人方面,而不是陷入不必要的复杂性。当然,确定你是否会觉得这个理论有趣的唯一方法是尝试学习它。

Read on and you will see that the theory is neither obscure nor arcane nor tedious, but quite understandable and downright interesting. Theoretical computer science contains many wonderful, grand ideas, although it is not without its small and sometimes boring details that can be tiresome. Learning new things is always difficult, but it can be made easier and more enjoyable if the material is properly presented. My main goal in writing this book is to introduce readers to the fascinating aspects of the theory of computation without getting bogged down in unnecessary complexities. Of course, the only way to find out whether you will find this theory interesting is to try to learn it.

理论与实践密切相关。它提供了从业者在计算机工程中使用的思维工具。您是否正在为特殊应用程序设计一种新的编程语言?你学到的语法知识将会派上用场。您进行单词搜索和模式匹配吗?记住有限自动机正则表达式。您是否面临着一个似乎需要比您分配的时间更多的时间来解决的问题?想想你对 NP 完备性的了解。各种应用领域,例如现代密码协议,都是基于您将在本书中学到的理论原理。

Theory is closely related to practice. It provides the thinking tools that practitioners use in computer engineering. Are you designing a new programming language for a special purpose? What you learn about grammars will come in handy . Are you doing word searches and pattern matching? Remember finite automata and regular expressions . Are you faced with a problem that seems to take longer to solve than you can spare? Think about what you learned about NP-completeness. Various application areas, such as modern cryptographic protocols, rely on the theoretical principles you learn in this book.

该理论也很重要,因为它展示了计算机新的、更简单的和更优雅的一面,而计算机通常被认为是非常复杂的机器。最好的计算机和应用程序设计源自优雅的概念。理论讲座可以增强你的审美意识,帮助你构建更漂亮的系统。

Theory is also important because it shows a new, simpler, and more elegant side to computers, which are usually considered very complex machines. The best computer and application designs emerge from elegant concepts. Theoretical instruction can enhance the aesthetic sense and help build more beautiful systems.

最后,理论是好的,因为研究它可以开发思想。计算机技术正在迅速变化。详细的技术知识虽然现在有用,但几年后就会过时。因此,值得培养清晰准确地思考和表达自己的能力,以便能够解决问题并知道我们何时无法解决问题。这些技能具有持久的价值。通过学习理论,我们在这些领域进行实践。

Finally, theory is good because studying it develops the mind. Computer technology changes rapidly. Detailed technical knowledge, although useful now, will become obsolete in a few years. It is therefore worth developing the ability to think, to express oneself clearly and precisely, to be able to solve problems and to know when we have not been able to solve a problem. Such skills have lasting value. By studying theory, we practice in these areas.

除了实际用途问题之外,几乎每个在工作中使用计算机的人都对这些非凡的创造、它们的可能性和局限性感到好奇。在过去的三十年里,一个新的数学分支已经发展起来,研究人员在其中寻找某些基本问题的答案。还有一个悬而未决的问题:如果我们取一个很大的数字(比如 500 位数字),我们能否在合理的时间内找到它的约数(除以它而没有余数的数字)?即使使用超级计算机,目前也没有人知道如何在小于宇宙年龄的时间内针对每种情况执行此操作!因式分解问题(即分解问题)与现代加密系统密切相关。找到一种快速分解数字的方法,您就会出名!

Aside from their practical utility, almost everyone who uses computers at work is curious about these amazing creations, their capabilities, and their limitations. Over the past thirty years, a new branch of mathematics has emerged, whose researchers are trying to answer some fundamental questions. Here is one that remains unsolved: If we take a large number—say, 500 digits—can we find its divisors (the numbers by which it divides without remainder) in a reasonable amount of time? Even with a supercomputer, no one currently knows how to do this for every case in less than the age of the universe ! The factoring problem (or the problem of factoring) is closely related to modern encryption systems. Find a fast way to factor a number, and you will become famous!

致老师们

To teachers

本书旨在作为理论计算机科学领域的教科书,供硕士研究生以及学士和工程研究的高年级学生使用。这些问题是基于定理和证明以数学方式提出的。我已经尽力向那些缺乏定理证明经验的学生介绍,但是更高级的学生会发现它更容易。

This book is intended as a textbook on theoretical computer science for graduate students and advanced undergraduate and graduate students. The topics are presented mathematically, based on theorems and proofs. I have made an effort to introduce students who have little experience in proving theorems, but more advanced students will find it easier.

我的主要目标是以清晰有趣的方式呈现材料。正因为如此,我更喜欢直觉和大局,而不是对底层细节的详细分析。

My main goal was to present the material in a clear and interesting way. For this reason, I favored intuition and the big picture over detailed analysis of lower-level details.

例如,虽然我在第Ø章中介绍了归纳证明方法以及其他数学基础,但它在本书的其余部分中并没有发挥重要作用。一般来说,我不会展示关于自动机的各种结构的正确性的典型归纳证明。如果表述清楚,这样的解释就可以为自己辩护,不需要进一步的论证。归纳法可能会掩盖而不是澄清问题,因为它本身是一种相当复杂的技术,对许多人来说是难以理解的。通过归纳法解释明显的事实存在着让学生永远相信数学证明是形式操纵的一种形式的风险,而不是教他们区分令人信服的论点和不令人信服的论点。

For example, although I have presented the method of proof by induction in Chapter Ø, along with other mathematical foundations, it does not play an important role in the rest of the book. In general, I do not present typical inductive proofs of the correctness of various constructions concerning automata. If they are presented clearly, such constructions are self-defeating and do not require further justification. Induction could obscure rather than clarify the problem, since it is in itself a rather sophisticated technique that many people do not understand. Explaining obvious facts by induction runs the risk of perpetuating the idea that mathematical proof is a kind of formal manipulation, instead of teaching them to distinguish convincing arguments from unconvincing ones.

第二个例子出现在第二部分和第三部分中,我用日常语言而不是使用伪代码描述算法。我没有花太多时间对图灵机(或任何其他正式模型)进行编程。今天的学生都有编程背景,丘奇-图灵假设对他们来说是显而易见的。因此,我不会通过一个模型对另一个模型进行长时间的模拟来证明它们的等效性。

The second example occurs in Parts 2 and 3, where I describe algorithms in everyday language rather than using pseudocode. I have not spent much time programming Turing machines (or any other formal model). Today's students have a programming background, and the Church-Turing thesis is obvious to them. So I do not present long simulations of one model by the other to show their equivalence.

尽管我更重视直觉并省略了某些细节,但我以一种可以称为经典的方式呈现材料。大多数理论家会发现材料的选择、术语和呈现顺序与其他广泛使用的教科书中包含的内容一致。当我发现常用术语特别不清楚或令人困惑时,我只在少数地方引入了我自己原创的术语。例如,我引入了映射归约的概念,而不是多对一归约

Although I give more weight to intuition and omit some details, I present the material in a way that may be called classical. Most theorists will find that the choice of material, the terminology, and the order of presentation are consistent with those in other widely used textbooks. I have introduced my own original terminology only in a few places, where I found the standard concepts to be particularly obscure or confusing. For example, I have introduced the notion of reduction by mapping in place of many-to-one reduction .

通过解决问题进行练习是学习任何数学领域的基础。书中提出的任务分为两类:练习和任务。这些练习的目的是回忆和巩固定义和概念。这些任务需要一定的创造力。标有星号的任务更加困难。我试图让解决练习和任务成为对学生来说有趣的挑战。

Practicing by solving problems is the basis for learning any mathematical discipline. The problems presented in the book are divided into two categories: Exercises and Problems. The exercises are intended to recall and consolidate definitions and concepts. The problems require some creativity. Problems marked with an asterisk are more difficult. I tried to make solving both exercises and problems an interesting challenge for students.

第一版

First edition

《计算理论导论》首次以平装介绍性版本出版。第一版与初步版在几个重要方面有所不同。添加了最后三章:第 8 章关于内存复杂性,第 9 章关于不可计算问题,第 10 章关于复杂性理论的高级主题。第 6 章经过扩展,包含了可计算性理论中的几个广泛主题。其他章节也补充了额外的示例和练习。

Introduction to Computation Theory was first published as a paperback introductory edition. The first edition differs from the introductory edition in several important respects. Three final chapters have been added: Chapter 8 on memory complexity, Chapter 9 on uncomputable problems, and Chapter 10 on advanced topics in complexity theory. Chapter 6 has been expanded to include several extended topics in computability theory. Other chapters have also been supplemented with additional examples and exercises.

我从使用预印本版本的教师和学生那里收到的评论有助于完善第 0-7 章。当然,我也纠正了引起我注意的错误。

The comments I received from instructors and students using the preprint helped me refine Chapters 0–7. Naturally, I also corrected errors that were brought to my attention.

第 6 章和第 10 章回顾了可计算性和复杂性理论中的一些更高级的主题。它们并不像其他章节那样以全面和连贯的方式呈现主题。我添加这些章节是为了让教师选择学生可能感兴趣的可选主题。相同的问题属于不同的领域。其中一些,例如图灵可约性交替性,是本书中讨论的其他概念的直接扩展。其他的,例如可判定的逻辑理论密码学,只是对广泛研究领域的简要介绍。

Chapters 6 and 10 review several more advanced topics in computability and complexity theory. They are not intended to be as comprehensive or coherent as the other chapters. I have included these chapters to allow the teacher to select optional topics that may be of interest to students. The topics themselves belong to a variety of areas. Some, such as Turing reducibility or alternations , are direct extensions of other concepts discussed in the book. Others, such as decidable logical theories or cryptography , are only brief introductions to large areas of study.

作者须知

Notes to the author

互联网为作者和读者之间的互动创造了新的机会。我收到了许多包含建议、赞扬和批评的电子邮件,包括预发布中的错误报告。请继续写!我尝试在时间允许的情况下尽快回复每条消息。有关本书的信件应发送至的地址是

The Internet has opened up new possibilities for interaction between authors and readers. I have received many e-mails containing suggestions, compliments, and criticisms, including reports of errors in the initial edition. Please continue to write! I try to answer every message as time permits. The address for correspondence concerning this book is

sipserbook@math.mit.edu。

sipserbook@math.mit.edu.

包含该书勘误的网站也在持续维护中。该网站还可能包含对教师和学生有用的其他材料。如果您能提供有关在那里可以找到什么的信息,我将不胜感激。此页面位于:

There is also an ongoing website containing errata for the book. Other materials useful for teachers and students may also appear on this website. I would be grateful for information on what could be found there. This website is available at:

http://math.mit.edu/~sipser/book.html

http://math.mit.edu/~sipser/book.html .

致谢

Thanks

如果没有许多朋友、同事和家人的帮助,我不可能写出这本书。

I could not have written this book without the help of many friends, colleagues and my family.

我要感谢我的老师,他们帮助我塑造了我的科学观点和教学方法。其中有五个特别突出。我的导师曼努埃尔·布鲁姆(Manuel Blum)值得特别提及,因为他具有通过清晰的思维、热情和关怀来激励学生的非凡能力。他是我和许多其他人的榜样。我还感谢理查德·卡普 (Richard Karp) 向我介绍了复杂性理论,感谢约翰·艾迪生 (John Addison) 教我逻辑并创造了出色的作业问题,感谢尤里斯·哈特马尼斯 (Juris Hartmanis) 向我介绍了计算理论,感谢我的父亲教我数学基础知识、计算机和传播知识的艺术。

I would like to thank my teachers who helped shape my scientific views and teaching methods. Five of them stand out in particular. My advisor, Manuel Blum, deserves special mention for his exceptional ability to inspire students through the clarity of his ideas, his enthusiasm, and his care. He is a role model for me and many others. I am also grateful to Richard Karp for introducing me to the secrets of complexity theory, John Addison for teaching me logic and preparing great homework assignments, Juris Hartmanis for introducing me to the theory of computation, and my father for teaching me the basics of mathematics, the use of computers, and the art of communicating knowledge.

这本书是根据我过去 15 年在麻省理工学院所做的一次演讲的笔记编写的。它们是由参加我讲座的学生写下来的。我希望他们能原谅我没有提及他们所有人。多年来与我共事的助理 – Avrim Blum、Thang Bui、Benny Chor、Andrew Chou、Stavros Cosmadakis、Aditi Dhagat、Wayne Goddard、Parry Husbands、Dina Kravets、Jakov Kučan、Brian O'Neill、Ioana Popescu 和 Alex Russell – 帮助编辑和开发这些笔记。他们也是一些练习和任务的作者。

This book is based on lecture notes I have given at MIT over the past 15 years. They were written by students who attended my lectures. I hope they will forgive me for not mentioning them all. The assistants who have worked with me over the years—Avrim Blum, Thang Bui, Benny Chor, Andrew Chou, Stavros Cosmadakis, Aditi Dhagat, Wayne Goddard, Parry Husbands, Dina Kravets, Jakov Kučan, Brian O'Neill, Ioana Popescu, and Alex Russell—helped to edit and expand these notes. They also wrote some of the exercises and problems.

大约三年前,汤姆·莱顿说服我写一本关于计算理论的教科书。我已经思考这个问题有一段时间了,但正是汤姆的论点将理论转化为实践。我很感谢他在写书和其他事情上提供的大量建议。

Almost three years ago, Tom Leighton convinced me to write a textbook on the theory of computation. I had been thinking about it for some time, but it was Tom's reasoning that allowed me to turn the theory into practice. I am grateful to him for his advice on writing books and for many other things.

我要感谢 Eric Bach、Peter Beebee、Cris Calude、Marek Chrobak、Anna Chefter、Guang-Ien Cheng、Elias Dahlhaus、Michael Fischer、Steve Fisk、Lance Fortnow、Henry J 在本书写作期间提供的意见、评论和帮助。弗里德曼、杰克·福、西摩·金斯伯格、奥德·戈尔德赖希、布莱恩·格罗斯曼、大卫·哈雷尔、米夏·霍弗里、Dung T. Huynh、尼尔·琼斯、H.查德·莱恩、凯文·林、迈克尔·路易、西尔维奥·米卡利、村田忠雄、克里斯托斯。 Papadimitriou、Vaughan Pratt、Daniel Rosenband、Brian Scassellati、Ashish Sharma、Nir Shavit、Alexander Shen、Ilya Shlyakhter、Matt Stallmann、Perry Susskind、YC Tay、Joseph Traub、Osamu Watanabe、Peter Widmayer、David Williamson、Derick Wood 和 Charles Yang。

I would like to acknowledge the comments, suggestions, and assistance provided during the writing of this book by Eric Bach, Peter Beebee, Cris Calude, Marek Chrobak, Anna Chefter, Guang-Ien Cheng, Elias Dahlhaus, Michael Fischer, Steve Fisk, Lance Fortnow, Henry J. Friedman, Jack Fu, Seymour Ginsburg, Oded Goldreich, Brian Grossman, David Harel, Micha Hofri, Dung T. Huynh, Neil Jones, H. Chad Lane, Kevin Lin, Michael Loui, Silvio Micali, Tadao Murata, Christos Papadimitriou, Vaughan Pratt, Daniel Rosenband, Brian Scassellati, Ashish Sharma, Nir Shavit, Alexander Shen, Ilya Shlyakhter, Matt Stallmann, Perry Susskind, YC Tay, Joseph Traub, Osamu Watanabe, Peter Widmayer, David Williamson, Derick Wood, and Charles Yang.

以下人员提供了有助于改进本书的额外评论和反馈:Isam M. Abdelhameed、Eric Allender、Shay Artzi、Michelle Atherton、Rolfe Blodgett、Al Briggs、Brian E. Brooks、Jonathan Buss、Jin Yi Cai、Steve Chapel、David Chow、Michael Ehrlich、Yaakov Eisenberg、Farzan Fallah、Shaun Flisakowski、Hjalmtyr Hafsteinsson、CR Hale、Maurice Herlihy、Vegard Holmedahl、Sandy Irani、Kevin Jiang、Rhys Price Jones、James M. Jowdy、David M. Martin Jr.、Manrique Mata -Montero、Ryota Matsuura、Thomas Minka、Farooq Mohammed、Tadao Murata、Jason Murray、Hideo Nagahashi、Kazuo Ohta、Constantine Papageorgiou、Joseph Raj、Rick Regan、Rhonda A. Reumann、Michael Rintzler、Arnold L. Rosenberg、Larry Roske、Max Rozenoer、Walter L. Ruzzo、Sanatan Sahgal、Leonard Schulman、Steve Seiden、Joel Seiferas、Ambuj Singh、David J. Stucki、Jayram S. Thathachar、H. Venkateswaran、Tom Whaley、Christopher Van Wyk、Kyle Young 和 Kyoung Hwan Yun。

The following people provided additional comments and feedback that improved this book: Isam M. Abdelhameed, Eric Allender, Shay Artzi, Michelle Atherton, Rolfe Blodgett, Al Briggs, Brian E. Brooks, Jonathan Buss, Jin Yi Cai, Steve Chapel, David Chow, Michael Ehrlich, Yaakov Eisenberg, Farzan Fallah, Shaun Flisakowski, Hjalmtyr Hafsteinsson, C. R. Hale, Maurice Herlihy, Vegard Holmedahl, Sandy Irani, Kevin Jiang, Rhys Price Jones, James M. Jowdy, David M. Martin Jr., Manrique Mata-Montero, Ryota Matsuura, Thomas Minka, Farooq Mohammed, Tadao Murata, Jason Murray, Hideo Nagahashi, Kazuo Ohta, Constantine Papageorgiou, Joseph Raj, Rick Regan, Rhonda A. Reumann, Michael Rintzler, Arnold L. Rosenberg, Larry Roske, Max Rozenoer,Walter L. Ruzzo, Sanatan Sahgal, Leonard Schulman, Steve Seiden, Joel Seiferas, Ambuj Singh, David J. Stucki, Jayram S. Thathachar, H. Venkateswaran, Tom Whaley, Christopher Van Wyk, Kyle Young, and Kyoung Hwan Yun.

罗伯特·斯隆在他的演讲中使用了这本书的草稿,并从这次经历中给了我宝贵的反馈和想法。马克·赫施伯格 (Mark Herschberg)、太田一夫 (Kazuo Ohta) 和拉塔尼亚·斯威尼 (Latanya Sweeney) 阅读了部分手稿并提出了多次修改建议。 Shafi Goldwasser 帮助我准备了第 10 章的材料。

Robert Sloan used a working version of the book in his lecture and gave me invaluable feedback and ideas from that experience. Mark Herschberg, Kazuo Ohta, and Latanya Sweeney read parts of the manuscript and suggested numerous improvements. Shafi Goldwasser helped me with the material for Chapter 10.

我得到了来自 Superscript 的 William Baxter 的技术帮助,他编写了一个 L A T E X 宏包来实现本书的内部布局,还有麻省理工学院数学系的 Larry Nolan 的技术帮助,他确保一切正常。

I received technical assistance from William Baxter of Superscript, who wrote a L A T E X macro package that implemented the book's internal layout, and from Larry Nolan of the MIT mathematics department, who made sure everything worked.

很高兴与 PWS Publishing 团队合作创建最终版本。我只会提及迈克尔·舒格曼、大卫·迪茨、埃莉斯·凯撒、莫妮克·卡莱罗、苏珊·加兰和塔尼娅·布鲁尔,因为他们是我接触最多的人,但我意识到还有很多其他人也参与其中。感谢 Jerry Moore 的文案编辑、Diane Levy 的封面设计以及 Catherine Hawkes 的内部布局设计。

It was a pleasure to work with the team at PWS Publishing in creating the final version. I will mention Michael Sugarman, David Dietz, Elise Kaiser, Monique Calello, Susan Garland, and Tanja Brull, as they were the ones I had most contact with, but I know that many others were involved. Thanks to Jerry Moore for copyediting, Diane Levy for the cover design, and Catherine Hawkes for the internal layout design.

我们感谢美国国家科学基金会 CCR-9503322 拨款的支持。

We thank the National Science Foundation for support under Grant CCR-9503322.

我的父亲肯尼思·西普瑟和妹妹劳拉·西普瑟将书中的图画转换成电子形式。我的另一个姐姐凯伦·费什 (Karen Fisch) 将我们从各种计算机故障中解救出来,而我的母亲贾斯汀·西普瑟 (Justine Sipser) 则提供了慈母般的建议。我感谢他们所有人在困难的情况下提供的支持,包括疯狂的截止日期和抵制软件。

My father, Kenneth Sipser, and sister, Laura Sipser, converted the drawings in the book into electronic form. My other sister, Karen Fisch, rescued us from various computer troubles, and my mother, Justine Sipser, provided motherly advice. I thank them all for their support under difficult circumstances, including crazy deadlines and stubborn software.

最后,我向我的妻子伊娜和女儿雷切尔表示爱意。谢谢你忍受这一切。

Finally, my love goes out to my wife Ina and daughter Rachel. Thank you for bearing with me through it all.

迈克尔·西普瑟

Michael Sipser

马萨诸塞州剑桥,1996 年 10 月

Cambridge, Massachusetts, October 1996

第二版前言

Preface to the Second Edition

从我从这么多读者那里收到的电子邮件来看,第一版的最大缺点是甚至缺乏某些任务的示例解决方案。所以他们已经在这里了。现在,每一章都包含一个名为“选定解决方案”的新部分,该部分提供了该章中代表性练习和任务选择的答案。为了补充减少的自行解决任务选择,我还添加了许多新的练习和任务。讲师还可以订购包含其他解决方案的教师手册。为此,请联系www.course.com上列出的您的区域销售代表。

Judging from the emails I have received from so many readers, the biggest flaw in the first edition was the lack of sample solutions to at least some of the problems. Well, here they are. Each chapter now contains a new section entitled Selected Solutions , which provides answers to a representative selection of exercises and problems in that chapter. To supplement the reduced selection of problems for self-study, I have also added a number of new exercises and problems. Instructors can also order a Teacher's Manual with additional solutions. To do this, contact your regional sales representative listed on www.course.com .

许多读者要求更广泛地报道一些“标准”主题,特别是迈希尔-尼罗德定理和莱斯定理。我部分地满足了这些要求,将这些问题发展为问题并提出解决方案。我没有在正文中包含Myhill-Nerod定理,因为我认为本次讲座应该只提供有限自动机理论的介绍,而不是对其进行深入分析。在我看来,有限自动机在本书中的作用是为学生提供一个简单的形式化计算模型,作为更强大模型的前奏,并为后面的主题提供方便的示例基础。当然,有些人会更喜欢对这个主题进行更详细的处理,而另一些人则希望我完备省略对有限自动机的任何提及(或者至少不要使后续主题依赖于它们)。我没有将赖斯定理纳入本书的正文中,因为尽管它是证明不可判定性的有用工具,但有些学生可能会机械地使用它而没有真正理解问题。通过约简而不是赖斯定理来证明不可判定性,为复杂性理论中稍后出现的约简提供了更好的准备。

Many readers have requested more extensive treatment of some of the "standard" topics, in particular the Myhill-Nerod theorem and the Rice theorem. I have partially complied with these requests by developing these topics as problems with solutions. I have not included the Myhill-Nerod theorem in the main text, since I feel that this lecture should provide only an introduction to the theory of finite automata, not a thorough treatment of it. In my view, the role of finite automata in this book is to provide students with a simple formal model of computation as a prelude to more powerful models, and also to provide a convenient basis for examples in later topics. Of course, some will prefer a more detailed treatment of this topic, while others would like me to omit all mention of finite automata (or at least not make later topics dependent on them). I have not included Rice's theorem in the main text of this book because, although it is a useful tool for proving undecidability, some students might use it mechanically, without really understanding the nature of the problem. Proving undecidability by reduction rather than by Rice's theorem provides better preparation for the reductions that appear later in complexity theory.

我非常感谢我的助手帮助我开发了一些新任务和解决方案。他们是 Ilya Baran、Sergi Elizalde、Rui Fan、Jonathan Feldman、Venkatesan Guruswami、Prahladh Harsha、Christos Kapoutsis、Julia Khodor、Adam Klivans、Kevin Matulef、Ioana Popescu、April Rasala、Sofya Raskhodnikova 和 Iuliu Vasilescu。 Ching W. Law、Edmond Kayi Lee 和 Zulfikar Ramzan 也为解决方案的开发做出了贡献。感谢 Victor Shoup 找到了一种简单的方法来填补第一个版本中存在的概率素性算法分析中的空白。

I am indebted to my assistants who helped me develop some of the new problems and solutions. They are Ilya Baran, Sergi Elizalde, Rui Fan, Jonathan Feldman, Venkatesan Guruswami, Prahladh Harsha, Christos Kapoutsis, Julia Khodor, Adam Klivans, Kevin Matulef, Ioana Popescu, April Rasala, Sofya Raskhodnikova, and Iuliu Vasilescu. Ching W. Law, Edmond Kayi Lee, and Zulfikar Ramzan also contributed to the solutions. I thank Victor Shoup for finding a simple way to patch a gap in the analysis of the probabilistic primality algorithm that existed in the first edition.

感谢 Course Technology 的人们激励我和这个项目的其他参与者,特别是 Alyssia Pratt Aimee Poirier。还要非常感谢 Gerald Eisman、Weizhen Mao、Rupak Majumdar、Chris Umans 和 Christopher Wilson 的审阅。我还要感谢 Jerry Moore 在编辑文本方面所做的出色工作,以及 ByteGraphics 的 Laura Segel (lauras@bytegraphics.com) 提供的精美插图。

Thanks to the people at Course Technology for motivating me and the other participants in this project, especially Alyssia Pratt, Aimee Poirier. Many thanks to Gerald Eisman, Weizhen Mao, Rupak Majumdar, Chris Umans, and Christopher Wilson for their reviews. I am also indebted to Jerry Moore for his excellent work in copyediting, and to Laura Segel of ByteGraphics (lauras@bytegraphics.com) for her beautiful work with the figures.

我收到的电子邮件数量超出了我的预期。收到来自这么多地方的消息是一次很棒的经历,我已经尽力回复每个人 - 请原谅我错过的那些。我在这里提到那些对本次版本产生特别影响的人,但我要感谢大家的来信:

The number of emails I received exceeded my expectations. It was a wonderful experience to receive messages from so many places, and I tried to respond to everyone—I apologize to those I have missed. I include here those whose suggestions were particularly influential in this edition, but I thank all for their correspondence:

卢卡·阿塞托、阿拉什·阿夫坎普尔、罗斯托姆·阿加尼安、埃里克·阿伦德、卡伦·巴克什、布拉德·巴林格、雷·巴特库斯、路易斯·巴顿、阿诺德·贝克曼、米希尔·贝拉尔、凯文·特伦特·伯杰森、马修·伯曼、拉杰什·巴特、索梅纳特·比斯瓦斯、莱诺尔·布鲁姆、毛罗·A·博纳蒂保罗·邦丁,尼古拉斯·博恩,伊恩·布拉特,吉恩·布劳德,道格·伯克,萨姆·巴斯,弗拉基米尔·比奇科夫斯基,布鲁斯·卡尼尔,索玛·乔胡里,陈荣杰,萨米尔·乔普拉,本尼·乔,约翰·克劳森,艾莉森·科茨,安妮·康登,杰弗里·康斯丁、约翰·J·克拉谢尔、克劳德·克雷波、肖恩·卡茨、苏谢尔·M·达斯瓦尼、杰夫·戴维斯、斯科特·德克斯特、彼得·德雷克、杰夫·埃德蒙兹、雅科夫·艾森伯格、库尔特塞贝·埃罗格鲁、乔治·埃斯尔、亚历山大·T·费德、法尔赞·法拉、菲斯·费奇、约瑟夫E. Fitzgerald、佩里·菲扎诺、大卫·福特、Jeannie Fromer、Kevin Fu、Atsushi Fujioka、Michel Galley、K. Ganesan、Simson Garfinkel、Travis Gebhardt、Peymann Gohari、Ganesh Gopalakrishnan、Steven Greenberg、Larry Griffith、Jerry Grossman、Rudolf de Haan , 迈克尔·哈尔珀, 尼克·哈维, 麦克·亨德里克斯, 劳里·希亚库莫托, 史蒂夫·霍克马, 迈克尔·赫勒, 沙哈达特·侯赛因, 戴夫·伊塞克, 盖斯·伊萨, Raj D. Iyer, 克里斯蒂安·雅各比, 托马斯·詹森, 迈克·D·琼斯, 马克斯·卡诺维奇, 亚伦·考夫曼, Roger Khazan、Sarfraz Khurshid、Kevin Killourhy、Seungjoo Kim、Victor Kuncak、Kanata Kuroda、Thomas Lasko、Suk Y. Lee、Edward D. Legenski、Li-Wei Lehman、Kong Lei、Zsolt Lengvarszky、Jeffrey Levetin、Baekjun Lim、Karen Livescu , 史蒂芬·路易, Tzer Hung Low, 沃尔夫冈·马斯, 阿拉什·马达尼, 迈克尔·马纳帕特, 沃伊切赫·马尔丘卡, 小大卫·M·马丁, 安德斯·马丁森, 莱尔·麦克乔奇, 阿尔贝托·梅迪纳, 库尔特·梅尔霍恩, 尼哈尔·梅塔, 艾伯特·R·迈耶, 托马斯·敏卡, Mariya Minkova、Daichi Mizuguchi、G. Allen Morris III、Damon Mosk-Aoyama、牟晓龙、Paul Muir、German Muller、Donald Nelson、Gabriel Nivasch、Mary Obelnicki、Kazuo Ohta、Thomas M. Oleson, Jr.、Curtis Oliver、Owen奥齐尔, 雷内·佩拉尔塔, 亚历山大·佩里斯, 霍尔格·彼得森, 德特勒夫·普朗普, 罗伯特·普林斯, 大卫·普里查德, 比娜·里德, 尼古拉斯·莱利, 罗纳德·里维斯特, 罗伯特·罗宾逊, 克里斯蒂·洛克威尔, 菲尔·罗格威, 马克斯·罗泽诺尔, 约翰·拉普夫, 特奥多·罗斯, 拉里·鲁佐,布莱恩·桑德斯、Cem Say、Kim Schioett、乔尔·塞费拉斯、若昂·卡洛斯·塞图巴尔、杰夫·李·塞永、马克·斯坎德拉、鲍勃·斯隆、杰夫·史密斯、马克·L·史密斯、斯蒂芬·史密斯、亚历克斯·C·斯诺伦、盖伊·圣丹尼斯、拉里·斯托克梅尔、 Radu Stoleru、David Stucki、Hisham M. Sueyllam、Kenneth Tam、Elizabeth Thompson、Michel Toulouse、Eric Tria、Chittaranjan Tripathy、Dan Trubow、Hiroki Ueda、Giora Unger、Kurt L. Van Etten、Jesir Vargas、Bienvenido Velez-Rivera、Kobus Vos、Alex Vrenios、Sven Waibel、Marc Waldman、Tom Whaley、Anthony Widjaja、Sean Williams、Joseph N. Wilson、Chris Van Wyk、邢光明、Vee Voon Yee、程永熙、Neal Young、Timothy Yuen、Kyle Yung、张京华,莉拉·佐莱。

Luca Aceto, Arash Afkanpour, Rostom Aghanian, Eric Allender, Karun Bakshi, Brad Ballinger, Ray Bartkus, Louis Barton, Arnold Beckmann, Mihir Bellare, Kevin Trent Bergeson, Matthew Berman, Rajesh Bhatt, Somenath Biswas, Lenore Blum, Mauro A. Bonatti , Paul Bondin, Nicholas Bone, Ian Bratt, Gene Browder, Doug Burke, Sam Buss, Vladimir Bychkovsky, Bruce Carneal, Soma Chaudhuri, Rong-Jaye Chen, Samir Chopra, Benny Chor, John Clausen, Allison Coates, Anne Condon, Jeffrey Considine , John J. Crashell, Claude Crepeau, Shaun Cutts, Susheel M. Daswani, Geoff Davis, Scott Dexter, Peter Drake, Jeff Edmonds, Yaakov Eisenberg, Kurtcebe Eroglu, Georg Essl, Alexander T. Fader, Farzan Fallah, Faith Fich, Joseph E. Fitzgerald, Perry Fizzano, David Ford, Jeannie Fromer, Kevin Fu, Atsushi Fujioka, Michel Galley, K. Ganesan, Simson Garfinkel, Travis Gebhardt, Peymann Gohari, Ganesh Gopalakrishnan, Steven Greenberg, Larry Griffith, Jerry Grossman, Rudolf de Haan, Michael Halper, Nick Harvey, Mack Hendricks, Laurie Hiyakumoto, Steve Hockema, Michael Hoehle, Shahadat Hossain, Dave Isecke, Ghaith Issa, Raj D. Iyer, Christian Jacobi, Thomas Janzen, Mike D . Jones, Max Kanovitch, Aaron Kaufman, Roger Khazan, Sarfraz Khurshid, Kevin Killourhy, Seungjoo Kim, Victor Kuncak, Kanata Kuroda, Thomas Lasko, Suk Y. Lee, Edward D. Legenski, Li-Wei Lehman, Kong Lei, Zsolt Lengvarszky, Jeffrey Levetin, Baekjun Lim, Karen Livescu, Stephen Louie, Tzer Hung Low, Wolfgang Maass, Arash Madani, Michael Manapat, Wojciech Marchewka, David M. Martin Jr., Anders Martinson, Lyle McGeoch, Alberto Medina, Kurt Mehlhorn, Nihar Mehta, Albert R. Meyer, Thomas Minka, Mariya Minkova, Daichi Mizuguchi, G. Allen Morris III, Damon Mosk-Aoyama, Xiaolong Mou, Paul Muir, German Muller, Donald Nelson, Gabriel Nivasch, Mary Obelnicki, Kazuo Ohta , Thomas M. Oleson, Jr., Curtis Oliver, Owen Ozier, Rene Peralta, Alexander Perlis, Holger Petersen, Detlef Plump, Robert Prince, David Pritchard, Bina Reed, Nicholas Riley, Ronald Rivest, Robert Robinson, Christi Rockwell, Phil Rogaway, Max Rozenoer, John Rupf, Teodor Rus, Larry Ruzzo, Brian Sanders, Cem Say, Kim Schioett, Joel Seiferas, Joao Carlos Setubal, Geoff Lee Seyon, Mark Skandera, Bob Sloan, Geoff Smith, Marc L. Smith, Stephen Smith , Alex C. Snoeren, Guy St-Denis, Larry Stockmeyer, Radu Stoleru, David Stucki, Hisham M. Sueyllam, Kenneth Tam, Elizabeth Thompson, Michel Toulouse, Eric Tria, Chittaranjan Tripathy, Dan Trubow, Hiroki Ueda, Giora Unger, Kurt L. Van Etten, Jesir Vargas, Bienvenido Velez-Rivera, Kobus Vos, Alex Vrenios, Sven Waibel, Marc Waldman, Tom Whaley, Anthony Widjaja, Sean Williams, Joseph N. Wilson, Chris Van Wyk, Guangming Xing, Vee Voon Yee, Cheng Yongxi, Neal Young, Timothy Yuen, Kyle Yung, Jinghua Zhang, Lilla Zollei.

还要感谢那些指出第一版中错误的人:Suzanne Balik、Matthew Kane、Kurt L. Van Etten、Nancy Lynch、Gregory Roberts 和 Cem Say。

Thanks are also due to those who pointed out errors in the first edition: Suzanne Balik, Matthew Kane, Kurt L. Van Etten, Nancy Lynch, Gregory Roberts, and Cem Say.

最重要的是,我要感谢我的家人——艾娜(Ina)、雷切尔(Rachel)和亚伦(Aaron)——当我无休止地坐在电脑屏幕前时,他们的耐心、理解和关爱。

Most of all, I would like to thank my family – Ina, Rachel and Aaron – for their patience, understanding and affection as I spent endless hours in front of my computer screen.

迈克尔·西普瑟

Michael Sipser

马萨诸塞州剑桥,2004 年 12 月

Cambridge, Massachusetts, December 2004

第三版前言

Preface to the Third Edition

第三版包括关于确定性上下文无关语言的全新部分。我选择这个主题有几个原因。首先,它填补了先前自动机理论和形式语言方法中的明显空白。旧版本介绍了有限状态自动机和图灵机的确定性和非确定性变体的概念,但我只讨论了堆叠自动机的非确定性版本。添加对确定性堆叠自动机的讨论是拼图中缺失的部分。

The third edition includes an entirely new section on deterministic context-free languages. I chose this topic for several reasons. First, it fills an obvious gap in previous approaches to automata theory and formal languages. Older editions introduced the concepts of finite automata and Turing machines in deterministic and nondeterministic varieties, but in those editions I discussed only the nondeterministic versions of pushdown automata. The addition of a discussion of deterministic pushdown automata is the missing piece of the puzzle.

其次,确定性上下文无关语言的理论是LR( k )语法的基础,它是自动机理论在编程语言和编译器设计中的一个重要且不平凡的应用。该应用程序结合了许多关键概念,包括确定性和非确定性有限自动机的等效性以及上下文无关语法到堆叠自动机的转换,反之亦然,从而产生了高效且美观的解析方法。所以在这里我们实现了理论与实践的真正合作。

Second, the theory of deterministic context-free languages ​​is the basis of LR( k ) grammars, an important and nontrivial application of automata theory to the design of programming languages ​​and compilers. This application combines many key ideas, including the equivalence of deterministic and nondeterministic finite automata and the transformation of context-free grammars to pushdown automata and back, leading to an efficient and beautiful method of parsing. So we have a real interaction of theory and practice.

最后,鉴于该主题作为自动机理论的自然应用的重要性,现有的计算理论教科书似乎没有充分涵盖该主题。我几年前研究过LR( k ) 语法,但我并没有完备理解它们是如何工作的以及它们如何完美地融入确定性上下文无关语言的理论。在撰写本节时,我的目的是为理论家和实践者提供对该领域直观而严谨的介绍,从而有助于更广泛地理解这些问题。不过,我必须补充一点:本章节中的一些内容要求很高,所以第一堂基础理论课的老师可以选择它作为补充阅读。后面的章节不依赖或参考本子章节的内容。

Finally, this topic seems to be insufficiently covered in existing textbooks on the theory of computation, given its importance as a natural application of automata theory. I studied LR( k ) grammars years ago, but I did not fully understand how they work and did not see how beautifully they fit into the theory of deterministic context-free languages. In writing this section, I have aimed to provide an intuitive but rigorous introduction to the field for both theorists and practitioners, and thus to contribute to a wider appreciation of the subject. I must add a warning, however: some of the material in this section is quite demanding, so a teacher giving a first, basic lecture on theory may choose it as additional reading. Later chapters do not depend on, and do not refer to, the content of this section.

许多人直接或间接地为这个版本的创作做出了贡献。我感谢审稿人 Christos Kapoutsis 和 Cem Say,他们阅读了新部分的草稿并分享了宝贵的意见。来自 Cengage Learning 的许多人都参与了制作,尤其是艾莉莎·普拉特 (Alyssa Pratt) 和詹妮弗·费尔特里-乔治 (Jennifer Feltri-George)。 Suzanne Huizenga 编辑了文本,ByteGraphics 的 Laura Segel 创建了新插图并修改了一些旧绘图。

Many people contributed directly or indirectly to this edition. I am grateful to reviewers Christos Kapoutsis and Cem Say, who read the draft of the new part and provided valuable feedback. Many people at Cengage Learning contributed to the production, especially Alyssa Pratt and Jennifer Feltri-George. Suzanne Huizenga edited the text, and Laura Segel of ByteGraphics provided new illustrations and modified some of the older figures.

我要感谢我的麻省理工学院助理 Victor Chen、Andy Drucker、Michael Forbes、Elena Grigorescu、Brendan Juba、Christos Kapoutsis、Jon Kelner、Swastik Kopparty、Kevin Matulef、Amanda Redlich、Zack Remscrim、Ben Rossman、Shubhangi Saraf 和 Oren Weimann 。他们每个人都通过讨论新任务及其解决方案来帮助我,并深入了解我们的学生对讲座内容的理解程度。与这些才华横溢、充满热情的年轻人一起工作真的很高兴。

I would like to thank my assistants at MIT, Victor Chen, Andy Drucker, Michael Forbes, Elena Grigorescu, Brendan Juba, Christos Kapoutsis, Jon Kelner, Swastik Kopparty, Kevin Matulef, Amanda Redlich, Zack Remscrim, Ben Rossman, Shubhangi Saraf, and Oren Weimann. Each of them helped me by discussing new problems and their solutions and by giving me insight into how well our students understood the content of the lecture. It is a real pleasure to work with such talented and enthusiastic young people.

最大的奖励是收到来自世界各地的带有注释和评论的电子邮件。感谢您提出的所有建议、问题和想法。以下是影响本版评论的通讯员名单:

It is a great reward to receive emails with comments and feedback from all over the world. Thank you for all your suggestions, questions and ideas. Here is a list of those correspondents whose comments have influenced this edition:

吉赫德·阿菲菲,史蒂夫·奥尔德里奇,埃里克·巴克,苏珊娜·巴利克,维克多·班杜尔,保罗·比姆,埃拉扎尔·伯恩鲍姆,古塔姆·比斯瓦斯,罗布·比特纳,玛丽娜·布兰顿,罗德尼·布利斯,普罗米塔·查克拉博蒂,刘易斯·科利尔,乔纳森·德伯,西蒙·德克斯特,马特·迪普豪斯,彼得·迪林杰, Peter Drake, 杜志典, Peter Fejer, 玛格丽特·弗莱克, Atsushi Fujioka, Valerio Genovese, Evangelos Georgiadis, Joshua Grochow, Jerry Grossman, Andreas Guelzow, Hjalmtyr Hafsteinsson, Arthur Hall III, Cihat Imamoglu, Chinawat Isradisaikul, Kayla Jacobs, Flemming Jensen,芭芭拉·凯撒、马修·凯恩、克里斯托斯·卡普西斯、阿里·杜洛夫·汗、埃德温·邱诗伦、金容旭、阿卡什·库马尔、埃利亚撒·莱尔、兹索尔特·伦瓦尔斯基、李正中、梁向东、弗拉基米尔·利夫希茨、瑞恩·洛蒂、乔纳森·洛、南希·林奇、亚历克西斯·马西尔, 凯文·马图莱夫, 纳尔逊·马克斯, 汉斯-鲁道夫·梅斯, 姆拉登·米克·扎,萨拉·迈纳·莫尔, Rajagopal Nagarajan, 马文·中山, 乔纳斯·尼拉普, 格雷戈里·罗伯茨, 瑞安·罗梅罗, 桑托什·萨马蒂亚姆, Cem Say, 乔尔·塞弗拉斯, 约翰·西格,马克·史密斯、约翰·斯坦伯格、努里·塔斯德米尔、塔米尔·塔萨、马克·特斯塔、杰西·张、约翰·特拉梅尔、Hiroki Ueda、Jeroen Vaelen、Kurt L. Van Etten、Guillermo Vazquez、Phanisekhar Botlaguduru Venkata、Benjamin Bing-Yi Wang、Lutz Warnke 、大卫·沃伦、托马斯·沃森、约瑟夫·威尔逊、大卫·维滕伯格、布莱恩·旺乔瓦特、基山·耶鲁班迪、戴毅。

Djihed Afifi, Steve Aldrich, Eirik Bakke, Suzanne Balik, Victor Bandur, Paul Beame, Elazar Birnbaum, Goutam Biswas, Rob Bittner, Marina Blanton, Rodney Bliss, Promita Chakraborty, Lewis Collier, Jonathan Deber, Simon Dexter, Matt Diephouse, Peter Dillinger , Peter Drake, Zhidian Du, Peter Fejer, Margaret Fleck, Atsushi Fujioka, Valerio Genovese, Evangelos Georgiadis, Joshua Grochow, Jerry Grossman, Andreas Guelzow, Hjalmtyr Hafsteinsson, Arthur Hall III, Cihat Imamoglu, Chinawat Isradisaikul, Kayla Jacobs, Flemming Jensen, Barbara Kaiser, Matthew Kane, Christos Kapoutsis, Ali Durlov Khan, Edwin Sze Lun Khoo, Yongwook Kim, Akash Kumar, Eleazar Leal, Zsolt Lengvarszky, Cheng-Chung Li, Xiangdong Liang, Vladimir Lifschitz, Ryan Lortie, Jonathan Low, Nancy Lynch, Alexis Maciel, Kevin Matulef, Nelson Max, Hans-Rudolf Metz, Mladen Mik Ŝ a, Sara Miner More, Rajagopal Nagarajan, Marvin Nakayama, Jonas Nyrup, Gregory Roberts, Ryan Romero, Santhosh Samarthyam, Cem Say, Joel Seiferas, John Sieg, Marc Smith, John Steinberger, Nuri Tas¸demir, Tamir Tassa, Mark Testa, Jesse Tjang, John Trammell, Hiroki Ueda, Jeroen Vaelen, Kurt L. Van Etten, Guillermo Vazquez, Phanisekhar Botlaguduru Venkata, Benjamin Bing-Yi Wang, Lutz Warnke, David Warren, ThomasWatson, Joseph Wilson, David Wittenberg, Brian Wongchaowart, Kishan Yerubandi, Dai Yi.

最重要的是,我要感谢我的家人——我的妻子伊娜(Ina)和我们的孩子雷切尔(Rachel)和亚伦(Aaron)。时间是有限的,而且过得很快。你的爱就是一切。

Above all, I thank my family – my wife Ina and our children Rachel and Aaron. Time is finite and slipping away. Your love is everything.

迈克尔·西普瑟

Michael Sipser

马萨诸塞州剑桥,2012 年 4 月

Cambridge, Massachusetts, April 2012

0

简介

0

Introduction

我们将从本书中介绍的计算理论领域开始。然后,读者将有机会学习和/或回忆他或她稍后需要的某些数学概念。

We will begin by reviewing the areas of computational theory that will be covered in this book. Then, the reader will have the opportunity to learn and/or refresh their memory on some of the mathematical concepts that they will need later.

0.1

自动机、可计算性和复杂性

0.1

Automata, Computability and Complexity

本书重点关注传统上与计算理论相关的三个领域:自动机、可计算性和复杂性。这些领域通过以下问题联系起来:

This book focuses on three areas traditionally associated with the theory of computation: automata, computability, and complexity. These areas are united by the question:

计算机的基本功能和局限性是什么?

What are the fundamental capabilities and limitations of computers?

这个问题可以追溯到 20 世纪 30 年代,当时数理逻辑学家首次开始考虑计算的本质。从那时起,技术进步极大地提高了我们的计算能力,这意味着这个问题不再是理论领域,而是成为实际应用领域的一部分。

The question goes back to the 1930s, when mathematical logicians first began to ponder the nature of computation. Technological advances since then have greatly expanded our computational abilities and moved the question from the realm of theory to the world of practical applications.

在自动机、可计算性和复杂性这三个领域中,这个问题有不同的解释,并且答案根据这种解释而变化。在这一介绍性章节之后,我们将在本书的不同部分中探讨每个领域。这里我们将以相反的顺序展示这些部分,因为从最后开始,读者将能够更好地理解开头的情况。

In each of these three areas—automata, computability, and complexity—the question is interpreted differently, and the answers change according to that interpretation. After this introductory chapter, we will examine each of these areas in separate parts of the book. Here we will present the parts in reverse order, because by starting at the end the reader will be better able to understand the conditions at the beginning.

复杂性理论

Complexity theory

计算问题有很多种;有些很容易,有些则很难。例如,排序问题就是简单的问题之一。假设我们需要按升序排列数字列表。即使是一台小型计算机也可以很快地对一百万个数字进行排序。让我们将其与日程问题进行比较。假设我们需要找到整个大学的讲座时间表,满足一些合理的约束,例如不能同时在同一个房间进行两场讲座。规划问题似乎比排序问题困难得多。如果我们有一千个小组,即使使用超级计算机,也可能需要很长时间才能找到最佳时间表。

Computational problems come in all sorts; some are easy, others are really hard. For example, the sorting problem is one of the easy ones. Suppose we need to sort a list of numbers into ascending order. Even a small computer can sort a million numbers fairly quickly. Contrast this with the scheduling problem. Suppose we need to find a schedule of lectures for an entire university, while satisfying some reasonable constraints, such as that no two lectures can be held in the same room at the same time. The scheduling problem seems much harder than the sorting problem. If we have a thousand groups, finding the best schedule could take ages, even with a supercomputer.

是什么让一些问题计算起来困难而另一些问题却很容易?

What makes some problems computationally difficult and others easy?

这是复杂性理论的一个核心问题。重要的是,尽管我们进行了 40 多年的深入搜寻,但我们仍然不知道答案。稍后我们将更详细地探讨这个有趣的问题及其一些变体。

This is a central question in complexity theory. Importantly, we do not know the answer to it, despite intensive research over the past 40 years. We will explore this fascinating question and some of its variants in more detail later.

迄今为止,复杂性理论的一项重要进展是,研究人员发现了一种根据计算难度对问题进行分类的优雅方案。它类似于元素周期表,用于根据其化学性质对它们进行分类。使用这个框架,我们可以提供一种方法来查找某些问题在计算上困难的迹象,即使我们无法证明它们确实如此。

In one of the important advances in complexity theory to date, researchers have discovered an elegant scheme for classifying problems according to their computational difficulty. It is analogous to the periodic table of elements used to classify them according to their chemical properties. Using this scheme, we can provide a method for finding indications that certain problems are computationally difficult, even if we cannot prove that they are.

当面对计算上看似困难的问题时,我们有多种选择。首先,通过了解问题的哪个方面导致了这种困难,我们也许能够改变它,使问题变得更容易解决。其次,结果可能是一个不完美的解决方案就足够了。在某些情况下,找到一个近似最佳值的方法是很容易的。第三,有些问题只在最坏的情况下才困难,但在大多数其他情况下都很容易。根据应用程序的不同,我们可能会对偶尔非常慢但通常运行速度很快的过程感到满意。最后,可以考虑使用替代类型的处理(例如随机计算)来加速特定任务。

When faced with a problem that seems computationally difficult, we have several options. First, by understanding what aspect of the problem is causing the difficulty, we may be able to change it so that the problem becomes easier to solve. Second, it may turn out that an imperfect solution is sufficient. In certain situations, finding one that is only an approximation of the best is easy. Third, some problems are difficult only in the worst case, but are easy in most other situations. Depending on the application, we may be satisfied with a procedure that is occasionally very slow but usually runs quickly. Finally, we can consider alternative types of processing, such as randomized computation, which can speed up certain tasks.

复杂性理论直接影响的应用领域之一是古老的密码学领域。在大多数问题中,计算上简单的问题比困难的问题更受欢迎,因为简单的问题解决起来更便宜。密码学的不同寻常之处在于它要求计算问题变得困难而不是简单。在不知道秘密密钥或密码的情况下,秘密密码应该很难破解。复杂性理论引导密码学家解决计算难题,并在此基础上设计新密码。

One area of ​​application that complexity theory has had a direct impact on is the ancient field of cryptography. In most problems, easy problems are preferred over hard ones because it is cheaper to solve easy problems. Cryptography is unusual in that it requires that computational problems be hard, not easy. Secret ciphers should be difficult to break without knowledge of the secret key or password. Complexity theory has directed cryptographers toward hard problems, from which new ciphers have been designed.

可计算性理论

Computability theory

二十世纪上半叶,库尔特·哥德尔、艾伦·图灵和阿隆佐·丘奇等数学家发现,一些基本问题无法使用计算机解决。这种现象的一个例子是确定某个数学陈述是真是假的问题。这项任务是数学家的日常工作。使用计算机解决这个问题似乎是很自然的,因为它属于数学领域。然而,没有计算机算法可以完成这项任务。

In the first half of the twentieth century, mathematicians such as Kurt Gödel, Alan Turing, and Alonzo Church discovered that certain fundamental problems could not be solved by computers. An example of this phenomenon is the problem of determining whether a mathematical statement is true or false. This is a daily task for mathematicians. It would seem that solving it by computers would be natural, since it lies within the realm of mathematics. However, no computer algorithm can accomplish this task.

这一意义深远的成果的一个后果是关于计算机理论模型的思想的发展,这些思想最终将有助于构建真正的计算机。

One consequence of this profound result was the development of concepts for theoretical models of computers that should ultimately help in the construction of real computers.

可计算性和复杂性理论密切相关。在复杂性理论中,目标是将问题分为简单或困难;同时,在可计算性理论中,问题被分为可解决的问题和不可解决的问题。可计算性理论引入了复杂性理论中使用的许多概念。

Computability and complexity theories are closely related. In complexity theory, the goal is to classify problems as easy or hard; meanwhile, in computability theory, problems are classifiable as those that are solvable or those that are not. Computability theory introduces many concepts used in complexity theory.

自动机理论

Theory of automata

自动机理论涉及计算数学模型的定义和属性。这些模型在计算机科学的许多应用领域发挥着作用。其中一种模型称为有限状态机,用于文本处理、编译器和硬件的设计。另一种模型称为上下文无关语法,用于编程语言和人工智能设计。

Automata theory is concerned with the definitions and properties of mathematical models of computation. These models play a role in many applied areas of computer science. One of these models, called a finite-state automaton , is used in the design of text processing, compilers, and hardware. Another model, called a context-free grammar , is used in programming languages ​​and the design of artificial intelligence.

自动机理论是开始研究计算理论的好地方。可计算性和复杂性理论需要对计算机进行精确定义。自动机理论允许您练习计算的正式定义,因为它引入了与计算机科学其他非理论领域相关的想法。

Automata theory is an excellent place to start studying the theory of computation. Theories of computability and complexity require precise definitions of what a computer is. Automata theory allows for practice in formal definitions of computation, as it introduces ideas relevant to other, non-theoretical areas of computer science.

0.2

数学概念和术语

0.2

Mathematical Concepts and Terminology

与任何数学教科书一样,我们将首先讨论我们将使用的基本数学对象、工具和符号。

As with any math textbook, we will begin by discussing the basic mathematical objects, tools, and notations we will be using.

收成

Collections

集合是被视为一个单元的一组对象。集合可以包含任何类型的对象,包括数字、符号,甚至其他集合。集合中的对象称为元素。集合可以用多种方式进行形式化描述。

A set is a group of objects treated as a unit. Sets can contain any type of object, including numbers, symbols, and even other sets. The objects in a set are called elements . Sets can be formally described in a variety of ways.

第一个是在花括号中枚举集合的元素。于是,一个集合

The first one is to enumerate the elements of the set in curly brackets. Thus, the set

S = {7, 21, 57}

S = {7, 21, 57}

包含元素 7、21 和 57。符号ε分别表示属于和不属于该集合。我们可以写成 7 {7, 21, 57} 和 8 {7, 21, 57}。对于两个集合A和 B,我们说A是集合B子集,如果集合A的每个元素也是集合B的元素,我们将其写为⊆  B。如果AB的子集且不等于B 则称A是B的真子集,记作B 。  

contains elements 7, 21, and 57. The symbols and denote membership and non-membership, respectively. We can write 7 {7, 21, 57} and 8 {7, 21, 57}. For two sets A and  B, we say that A is a subset of B , which we write ⊆  B , if every element of A is also an element of B . We say that A is a proper subset of B , which we write  B , if A is a subset of B and not equal to B .

集合中元素的顺序并不重要,元素的重复也不重要。通过写成{57,7,7,7,21},我们将得到相同的集合S。如果我们想考虑元素出现的次数,我们将这样的组称为多重集,而不是集合。因此,{7} 和 {7, 7} 是不同的多重集,但它们作为集合是相同的。无限集合包含无限多个元素。不可能列出无限集合的所有元素,因此有时我们会使用符号“...”来表示“无限期地继续序列”。因此,我们可以将自然 集合N写为

The order of the elements in the set is not important, nor is the repetition of the elements. Writing {57, 7, 7, 7, 21} gives us the same set S . If we wanted to take into account the number of occurrences of the elements, we would call such a group a multiset , not a set. Thus, {7} and {7, 7} are different multisets, but they are identical as sets. An infinite set contains infinitely many elements. It is impossible to list all the elements of an infinite set, so sometimes we will use the notation "..." to mean "to continue the sequence into infinity". Thus, we can write the set of natural numbers N as

{1,2,3,…}。

{1, 2, 3, …}.

整数集合Z可以

The set of integers Z can be written as

{…,−2,−1, 0, 1, 2, …}。

{… ,−2,−1, 0, 1, 2, …}.

具有零个元素的集合称为空集,记为Ø。只包含一个元素的集合有时称为单例,包含两个元素的集合有时称为无序对

A set that has zero elements is called the empty set and is written as Ø . A set containing exactly one element is sometimes called a singleton , and a set with two elements is called an unordered pair .

当我们想要描述一个包含满足特定规则的元素的集合时,我们将其写为{ n :关于n的规则}。因此,{ n : n = m 2 for some m N } 表示构成自然数平方的数字集合。

When we want to describe a set containing elements satisfying a certain rule, we write it as { n : rule about n }. Thus, { n : n = m 2 for some m N } denotes the set of numbers that are the squares of the natural numbers.

给定两个集合A和 B,它们的写为A B ,是我们通过将集合A和 B的所有元素组合成一个而获得的集合。集合 A 和 B的交集公共部分) ,写作A B ,是同时属于AB的元素的集合。集合A补集,写作A ,是所考虑的域中不属于A 的所有元素的集合。

Given two sets A and  B , their union , written as A B , is the set obtained by combining all the elements of sets A and  B into one. The intersection ( common part ) of sets A and  B , written as A B , is the set of those elements that belong to both A and B . The complement of set A , written as A , is the set of all the elements of the domain under consideration that do not belong to A .

正如数学中常见的情况一样,绘图可以帮助阐明某些概念。对于集合,我们使用所谓的维恩图。它们将集合表示为包含在椭圆线内的区域。令集合 START- t为以字母t开头的所有单词的集合。在图中的这个例子中,圆圈代表集合START- t。该集合的几个元素表示为该圆内的点。

As often happens in mathematics, a drawing can help explain some concepts. For sets, we use so-called Venn diagrams . They represent sets as regions enclosed by oval lines. Let the set START- t be the set of all words starting with the letter t . In this example, a circle in the drawing denotes the set START- t . Several elements of this set are represented as points inside the circle.

0.1

以字母“ t ”开头的一组单词的维恩图

Figure 0.1

Venn diagram for the set of words starting with the letter " t "

类似地,在下图中,我们可以呈现由以字母“z”结尾的单词组成的 END-z 集合。

Similarly, in the next figure we can present the set END-z consisting of words ending with the letter "z".

0.2

以字母“z”结尾的英语单词集的维恩图

Figure 0.2

Venn diagram for the set of English words ending with the letter "z"

为了在同一个维恩图中表示这两个集合,我们需要将它们绘制为使圆圈重叠,表明它们具有一些共同元素,如下图所示。例如,单词“topaz”就属于这两个集合。该图还包含 START- j集的圆圈。它不会与 START -t集的圆圈重叠,因为没有单词可以同时属于这两个集。

To represent both sets in the same Venn diagram, we need to draw them so that the circles overlap, indicating that they have some elements in common, as in the following figure. For example, the word topaz belongs to both sets. This figure also contains a circle for the set START- j . It does not overlap the circle for the set START- t , since no word can belong to both sets.

0.3

重叠的圆圈表示共同元素

Figure 0.3

Overlapping circles indicate common elements

接下来的两个维恩图说明了集合A的并集和交集。

The next two Venn diagrams illustrate the union and intersection of sets A and  B .

0.4 (a) A B和 ( b ) A B

的图表

Figure 0.4

Diagrams for (a) A B and ( b ) A B

字符串和元组

Strings and tuples

序列是按特定顺序排列的某些对象的列表。通常通过将字符串的元素括在圆括号中来编写字符串。例如,字符串 7, 21, 57 可以写为

A sequence is a list of certain objects in a specific order. It is customary to write a sequence by placing its elements in parentheses. For example, the sequence 7, 21, 57 can be written as

(7、21、57)。

(7, 21, 57).

在集合中,元素的顺序并不重要,但在序列中,元素的顺序很重要。因此,(7,21,57)与(57,7,21)不是同一个序列。同样,序列中元素的重复很重要,尽管它在集合中无关紧要。这意味着序列 (7, 7, 21, 57) 与之前的两个序列不同,尽管集合 {7, 21, 57} 与集合 {7, 7, 21, 57} 相同。

In a set, the order of elements is irrelevant, but in a sequence it is significant. Thus, (7, 21, 57) is not the same sequence as (57, 7, 21). Similarly, the repetition of elements in a sequence is significant, but it is not significant in a set. This means that the sequence (7, 7, 21, 57) is different from both of the previous sequences, although the set {7, 21, 57} is identical to the set {7, 7, 21, 57}.

与集合一样,序列可以是有限的或无限的。有限序列通常称为元组。具有k 个元素的序列称为k 元组。所以 (7, 21, 57) 是一个三元组。 2 元组通常称为有序对- 类似地,我们使用有序三、四或五的概念。

As with sets, sequences can be finite or infinite. Finite sequences are often called tuples . A sequence with k elements is called a k-tuple . Thus, (7, 21, 57) is a 3-tuple. A 2-tuple is often called an ordered pair – we use the terms 3, 4, or 5 in analogy.

集合和字符串可以显示为其他集合和字符串的成员。例如,A集是A的所有子集的集合。如果A是集合 {0, 1},则幂集A就是集合 { Ø , {0}, {1}, {0, 1} }。所有元素为 0 和 1 的有序对的集合为 { (0, 0), (0, 1), (1, 0), (1, 1) }。

Sets and sequences can appear as elements of other sets and sequences. For example, the power set of A is the set of all subsets of A . If A is the set {0, 1}, then the power set of A is the set { Ø , {0}, {1}, {0, 1} }. The set of all ordered pairs whose elements are zeros and ones is { (0, 0), (0, 1), (1, 0), (1, 1) }.

如果A和 B是集合,那么它们的笛卡尔积,写作A × B,是所有有序对的集合,其中第一个元素属于集合A,第二个元素属于集合B。

If A and  B are sets, then their Cartesian product , written A × B , is the set of all ordered pairs such that the first element belongs to set A and the second element belongs to set B .

示例0.5

Example 0.5

如果A = {1, 2} B = { x , y , z },则

If A = {1, 2} and B = { x , y , z }, then

A × B = { (1, x ), (1, y ), (1, z ), (2, x ), (2, y ), (2, z ) }。

A × B = { (1, x ), (1, y ), (1, z ), (2, x ), (2, y ), (2, z ) }.

我们还可以对k个集合A 1 , A 2 , … , A k进行笛卡尔积,写为A 1 × A 2 × × A k。它是由所有k元组 ( a 1 , a 2 , …, a k )组成的集合,其中a i A i

We can also perform the Cartesian product of k sets A 1 , A 2 , … , A k , written as A 1 × A 2 × × A k . This is the set consisting of all k -tuples ( a 1 , a 2 , … , a k ) with a i A i .

示例 0.6

Example 0.6

如果 A 和 B是像示例 0.5 中那样的集合,则

If A and  B are sets such as in Example 0.5, then

A × B × A = { (1, x , 1), (1, x , 2), (1, y , 1), (1, y , 2), (1, z , 1), (1,, 2),

A × B × A = { (1, x , 1), (1, x , 2), (1, y , 1), (1, y , 2), (1, z , 1), (1, with , 2),

(2, x , 1), (2, x , 2), (2, y , 1), (2, y , 2), (2, z , 1), (2, z , 2)}。

(2, x , 1), (2, x , 2), (2, y , 1), (2, y , 2), (2, z , 1), (2, z , 2)}.

如果我们创建一个集合与其自身的笛卡尔积,我们可以使用简写符号

If we create the Cartesian product of a set with itself, we can use the shorthand notation

k

k

A × A × × A = A k

A × A × × A = A k .

示例 0.7

Example 0.7

集合N 2等于N × N。​它由所有有序的自然数对组成。我们也可以将其写为{( i , j ) : i , j ³ 1}。

The set N 2 is equal to N × N . It consists of all ordered pairs of natural numbers. We can also write it as {( i , j ) : i , j ³ 1}.

功能和关系

Functions and relationships

函数是数学的基础。函数是定义输入输出关系的对象。它接受输入(参数)并返回结果(值或函数输出)。在每个函数中,相同的参数必须始终返回相同的值。如果f是一个函数,其参数a的输出值为b,我们将其写为

Functions are the foundation of mathematics. A function is an object that defines an input-output relationship. It takes an input (an argument) and returns a result (a value, or the output of the function). In any function, the same argument must always return the same value. If f is a function whose output is b for an argument a , we write this as

f ( a ) = b

f ( a ) = b .

函数有时也称为映射:如果f ( a )= b,我们说f将a映射到b

A function is also called a map : if f ( a ) = b , we say that f maps from a to b .

例如,绝对值函数abs将数字x作为输入,如果x是正数则返回x ,如果x是负数则返回−x。因此,abs (2) = abs (−2) = 2。函数的另一个例子可能是加法,我们将其写为add。加法函数的输入是一对有序的数字,输出(值)是这些数字的和。

For example, the absolute value function abs takes a number x as input and returns x if x is positive, and − x if x is negative. Thus, abs (2) = abs (−2) = 2. Another example of a function is addition, which we write as add . The input to the addition function is an ordered pair of numbers, and the output (value) is the sum of those numbers.

函数的可能输入值的集合称为它的。结果(输出值)属于定义为函数的反域值集)的集合。 f是一个具有定义域D且值来自集合W 的函数的语句写为

The set of possible input values ​​of a function is called its domain . The results (output values) belong to the set defined as the codomain ( set of values) of the function. The statement that f is a function with domain D and values ​​from the set W , is written as

f : DW

f : DW .

对于函数abs,如果我们将自己限制为整数,则域和子域都是Z,因此我们可以写absZ Z。在整数加法函数的情况下,定义域是整数对Z ×  Z 的集合反定义域是Z,因此我们将写成addZ × Z Z 。请注意,函数不必使用指定值集的所有元素。例如,函数abs永远不会取值 -1,即使 -1 Z。使用一组值的所有元素的函数称为函数

In the case of the function abs , if we restricted ourselves to integers, both the domain and codomain are Z , so we can write abs : Z Z . In the case of the integer addition function, the domain is the set of pairs of integers Z  ×  Z , and the codomain is Z , so we can write add : Z × Z Z . Note that the function does not have to use all the elements of the specified set of values. For example, the function abs never takes the value −1, even though −1 Z . A function that uses all the elements of the set of values ​​is called an “onto” ( surjective ) function .

函数可以用多种方式表示。一种是计算给定输入值的输出值的过程。另一种方法是使用数组,枚举所有可能的参数并为每个参数提供值。

Functions can be represented in many ways. One is a procedure that calculates an output value for a given input value. Another method is an array that lists all possible arguments and provides values ​​for each.

示例 0.8

Example 0.8

考虑函数f:{0, 1, 2, 3, 4}→{0, 1, 2, 3, 4}。

Consider the function f : {0, 1, 2, 3, 4}→{0, 1, 2, 3, 4}.

n

n

f ( n )

f ( n )

0

0

1

1

1

1

2

2

2

2

3

3

3

3

4

4

4

4

0

0

此函数将参数加 1,并返回模 5 的结果。回想一下,模m 的数字是该数字除以m时的余数。例如,钟盘上的分针给出模 60 的值。当使用余数算术时,我们定义Z m = {0, 1, 2, …, m − 1}。通过这种表示法,前面提到的函数f的形式为f : Z 5  →  Z 5

This function adds 1 to its argument and returns the result modulo 5. Recall that a number modulo m is the remainder when dividing that number by m . For example, the minute hand on a clock face gives values ​​modulo 60. When using remainder arithmetic, we define Z m = {0, 1, 2, …, m − 1}. With this notation, the previously mentioned function f has the form f : Z 5  →  Z 5 .

示例0.9

Example 0.9

有时,当函数的域是两个集合的笛卡尔积时,会使用二维数组来表示其值。这是另一个函数g : Z 4  ×  Z 4  →  Z 4。行标记为i且列标记为j 的数组单元格包含值g ( i , j )。

Sometimes, when the domain of a function is the Cartesian product of two sets, a two-dimensional array is used to represent its values. Here is another function, g : Z 4  ×  Z 4  →  Z 4 . The array cell in the row labeled i and the column labeled j contains the value g ( i , j ).

G

g

0

0

1

1

2

2

3

3

0

0

0

0

1

1

2

2

3

3

1

1

1

1

2

2

3

3

0

0

2

2

2

2

3

3

0

0

1

1

3

3

3

3

0

0

1

1

2

2

g函数是模 4 的加法函数。

The g function is the addition function modulo 4.

如果对于某些集合A 1 , … , A k ,函数的域是A 1 ×· ·× A k ,则f 的输入是k元组 ( a 1 , a 2 , … , a k ) 并且个体a i称为函数f的参数。具有k 个参数的函数称为k 参数函数,k称为该函数的可论证性(有时称为aryness )。如果k为 1,则 f有一个参数,称为一元函数。如果k为 2,则 f双参数二元)函数。某些众所周知的双参数函数是使用特定的中缀表示法编写的,其中函数符号放置在两个参数之间,而不是通常使用的前缀表示法,其中函数符号位于参数之前。例如,加法函数add通常采用中缀表示法,参数之间加 + 符号,即a + b,而不是前缀表示法add ( a , b )。

If the domain of a function is A 1 × × A k for some sets A 1 , … , A k , the input f is a k -tuple ( a 1 , a 2 , … , a k ) and the individual a i are called the arguments of f . A function with k arguments is called a k-argument function , and k is called the arity of the function. If k is 1, f has a single argument and is called a unary function . If k is 2, f is a binary function . Certain well-known binary functions are written using a special infix notation , in which the function symbol is placed between the two arguments, rather than the more commonly used prefix notation , where the function symbol precedes the arguments. For example, the addition function add is conventionally written in infix notation with a + symbol between its arguments, i.e. a + b , rather than the prefix notation add ( a , b ).

谓词属性是一个函数,其反域是集合 {TRUE, FALSE}。例如,设Even为属性,如果参数为偶数,则计算结果为 TRUE;如果参数为奇数,则计算结果为 FALSE。因此,即使(4) = TRUE,甚至(5) = FALSE。

A predicate or property is a function whose codomain is the set {TRUE, FALSE}. For example, let even be a property that evaluates to TRUE if the argument is an even number and FALSE if it is an odd number. Thus, even (4) = TRUE and even (5) = FALSE.

定义域为k元组A × ... × A的集合的属性称为关系k 参数关系或A上的 k 参数关系。一个经常遇到的情况是双参数关系,也称为二元关系。在编写使用二元关系的表达式时,我们通常使用中缀表示法。例如,“小于”是一种传统上使用中缀符号 < 书写的关系。使用符号 = 书写的“平等”是另一种众所周知的关系。如果R是二元关系,则表达式aRb表示aRb = TRUE。类似地,如果Rk参数关系,则表达式R ( a 1 , …, a k ) 意味着R ( a 1 , …, a k ) = TRUE。

A property whose domain is the set of k -tuples A × × A is called a relation , a k-argument relation , or a k-argument relation on A . A common case is a binary relation, also called a binary relation. When writing expressions involving binary relations, we customarily use infix notation. For example, “less than” is a relation, which is customarily written using the infix symbol <. “Equality,” written using the symbol =, is another well-known relation. If R is a binary relation, the expression aRb means that aRb = TRUE. Similarly, if R is a k -argument relation , the expression R ( a 1 , …, a k ) means that R ( a 1 , …, a k ) = TRUE.

示例 0.10

Example 0.10

在石头、剪刀、布的游戏中,两个玩家同时从集合{剪刀、布、石头}中选择一个元素,并用他们的手的适当位置提出他们的选择。如果选择相同,则重复游戏。如果选择不同,则根据胜率,由一名玩家获胜

In the game of rock, paper, scissors, two players simultaneously select an element from the set {SCISSORS, PAPER, ROCK} and represent the selection by appropriately positioning their hands. If the selections are identical, the game is repeated. If the selections differ, one player wins according to the relationship of captures .

节拍

it beats

SHEARS

PAPER

石头

STONE

SHEARS

错误的

FALSE

真的

TRUE

错误的

FALSE

PAPER

错误的

FALSE

错误的

FALSE

真的

TRUE

石头

STONE

真的

TRUE

错误的

FALSE

错误的

FALSE

从该表中我们可以看出 SCISSORS击败PAPER 为 TRUE,PAPER 击败 SCISSORS 为 FALSE。

From this table we can read that SCISSORS beats PAPER is TRUE, while PAPER beats SCISSORS is FALSE.

有时将谓词表示为集合而不是函数更方便。谓词P : D →{TRUE, FALSE} 可以写为 ( D , S ),其中S = { a D : P ( a ) = TRUE} 或简单地写为S (如果D的域从上下文中显而易见)。因此,节拍关系可以写为

It is sometimes more convenient to represent predicates as sets rather than as functions. The predicate P : D →{TRUE, FALSE} can be written as ( D , S ), where S = { a D : P ( a ) = TRUE} or simply S , if the domain of D is obvious from the context. Thus, the bisecting relation can be written as

{(剪刀,布),(布,石头),(石头,剪刀)}。

{(SCISSORS, PAPER), (PAPER, ROCK), (ROCK, SCISSORS)}.

一种特殊类型的二元关系称为等价关系,它提出了两个对象在某些方面相等的概念。二元关系R是等价关系,如果它满足三个条件:

A special type of binary relation, called an equivalence relation , presents the notion of equality of two objects in some respect. A binary relation R is an equivalence relation if it satisfies three conditions:

  1. R自反的,即对于每个x都有xRx
  2. R is reflexive , that is, for every x, xRx holds ;
  3. R对称的,即对于所有xyxRy产生yRx;和
  4. R is symmetric , that is, for every x and y , xRy implies yRx ; and
  5. R传递性的,即对于所有xyz,如果xRyyRz,则xRz
  6. R is transitive , that is, for every x , y, and z , if xRy and yRz , then xRz .

示例 0.11

Example 0.11

让我们定义自然数的等价关系,写为7。对于i , Π Ni == 7 j,如果ij是 7 的倍数。这是一个等价关系,因为它满足上述三个条件。首先,它是自反的,因为i − i = 0,它是 7 的倍数。其次,它是对称的,因为如果i − j是 7 的倍数,那么我们可以检查j − i也是 7 的倍数第三,它是传递性的,因为如果i − j是 7 的倍数且j − k是 7 的倍数,则i − k = ( i − j ) + ( j − k ) 是两个倍数之和。 7,因此也是7的倍数。

Let us define an equivalence relation for the natural numbers, written as 7 . For i , Π N let i 7 j , if ij is a multiple of 7. This is an equivalence relation because it satisfies the three conditions mentioned. First, it is reflexive, since i − i = 0, which is a multiple of 7. Second, it is symmetric, since if i − j is a multiple of 7, then one can check that j − i is also a multiple of 7. Third, it is transitive, since if i − j is a multiple of 7 and j − k is a multiple of 7, then i − k = ( i − j ) + ( j − k ) is the sum of two multiples of 7, and is therefore also a multiple of 7.

图表

Graphs

无向图或简称是一组点,其中一些点通过线相互连接。这些点称为顶点节点,线称为,如下图所示。

An undirected graph , or simply a graph , is a set of points with lines connecting some of them. These points are called vertices or nodes , and the lines are called edges , as in the figure below.

0.12

图形示例

Figure 0.12

Examples of graphs

在特定顶点相交的边的数量称为该顶点的度。在图0.12(a)中,所有顶点的度数为2。在图0.12( b )中,所有顶点的度数为3。任意两个顶点之间最多允许有一条边。在某些情况下,我们可能允许从顶点到自身的边,即环回

The number of edges meeting at a particular vertex is called the degree of that vertex. In Figure 0.12(a) all vertices have degree 2. In Figure 0.12( b ) all vertices have degree 3. At most one edge is allowed between any two vertices. In some situations we may allow edges leading from a vertex to itself, i.e., loopbacks .

在包含顶点ij的图G中,对 ( i , j ) 表示连接这些顶点的边。在无向图中, ij的顺序并不重要,因此 ( i , j ) 和 ( j , i ) 对表示相同的边。无向边有时使用集合表示法表示为无序对,即 { i , j }。如果V是顶点G的集合,E是边的集合,我们可以将其写为G = ( VE )。我们可以使用图表或更正式地指定集合VE来表示图形。例如,图0.12(a)中图的形式化描述为

In a graph G containing vertices i and j, the pair ( i , j ) represents an edge connecting these vertices. The order of i and j does not matter in an undirected graph, so the pairs ( i , j ) and ( j , i ) represent the same edge. Undirected edges are sometimes represented as unordered pairs using set notation, that is, { i , j }. If V is the set of vertices of G and E is the set of edges, we can write this as G = ( VE ). We can represent the graph by diagramming or more formally by specifying the sets V and E . For example, the formal description of the graph in Figure 0.12(a) is

({1, 2, 3, 4, 5}, {(1, 2), (2, 3), (3, 4), (4, 5), (5, 1)}),

({1, 2, 3, 4, 5}, {(1, 2), (2, 3), (3, 4), (4, 5), (5, 1)}),

图0.12( b )中图的形式化描述为

and the formal description of the graph in Figure 0.12( b ) is

({1, 2, 3, 4}, {(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)})。

({1, 2, 3, 4}, {(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)}).

图表通常用于表示数据。顶点可以是城市,边可以是连接城市的道路,或者顶点可以代表人,边可以代表人与人之间的友谊。有时,为了方便起见,我们可以标记图的顶点和/或边,这称为标记图。图0.13显示了一个图,其顶点是城市,边用这些城市之间最便宜的直飞航班的成本来描述,如果这样的直飞(直飞)是可能的。

Graphs are often used to represent data. The vertices can be cities and the edges can be roads connecting them, or the vertices can represent people and the edges can represent friendships between them. Sometimes, for convenience, we can label the vertices and/or edges of a graph, which is then called a labeled graph . Figure 0.13 shows a graph whose vertices are cities and the edges are labeled with the cheapest direct flight between the cities, if such a direct (non-stop) flight is possible.

0.13

不同城市之间最便宜的直飞机票

Figure 0.13

The cheapest non-stop airfares between different cities

如果G 的顶点是H的顶点的子集并且G的边是对应顶点1的 H边,我们就说图G是图H的子图。下图显示了图H和子图G。

We say that a graph G is a subgraph of a graph H if the vertices of G are a subset of the vertices of H and the edges of G are the edges of H for the corresponding vertices 1 . The following figure shows a graph H and a subgraph of G .

0.14

G (显示较暗)是图H的子图

Figure 0.14

The graph G (shown in darker shade) is a subgraph of the graph H

图中的路径是由边连接的顶点序列。直线路径是没有重复顶点的路径。如果对于任何两个顶点都有一条连接它们的路径,则图是连通的。如果一条路径是封闭的,即在同一顶点开始和结束,则该路径称为循环。简单循环是由至少三个不同顶点组成的循环,其中仅重复第一个顶点(作为最后一个顶点)。如果图是连通的且不包含简单循环,则图是,如图 0.15( c ) 所示。一棵树可能包含一个特殊的顶点,称为。在树中,除了根之外,度数为1的顶点称为树的叶子。

A path in a graph is a sequence of vertices connected by edges. A simple path ( road ) is a path in which no vertex is repeated. A graph is connected if for any two vertices there is a path connecting them. A path is called a cycle if it is closed, i.e. it starts and ends at the same vertex. A simple cycle is a cycle consisting of at least three different vertices in which only the first vertex (as the last) is repeated. A graph is a tree if it is connected and does not contain simple cycles, as in Figure 0.15 ( c ). A tree may contain a specially distinguished vertex called the root . In a tree, except for the root, the vertices of degree 1 are called leaves of the tree.

0.15

(a)图中的路径,( b )图中的循环和( c )树

Figure 0.15

(a) A path in a graph, ( b ) a cycle in a graph, and ( c ) a tree

有向图使用箭头而不是直线表示,如下图所示。来自特定顶点的箭头的数量称为该顶点的输出度,指向给定顶点的箭头的数量称为其输入度

A directed graph is represented using arrows instead of lines, as shown in the next figure. The number of arrows leaving a given vertex is called the outdegree of that vertex, and the number of arrows pointing to a given vertex is called its indegree .

0.16

有向图

Figure 0.16

Directed graph

在有向图中,从顶点i到顶点j 的边表示为有序对 ( i , j )。有向图G的形式表示为 ( V , E ),其中V是顶点集,E - 边集。图 0.16 所示图表的正式表示法是

In a directed graph, an edge from vertex i to vertex j is represented as an ordered pair ( i , j ). The formal notation of a directed graph G is ( V , E ), where V is a set of vertices and E is a set of edges. The formal notation of the graph shown in Figure 0.16 is

({1,2,3,4,5,6}, {(1,2), (1,5), (2,1), (2,4), (5,4), (5,6 ), (6,1), (6,3)})。

({1,2,3,4,5,6}, {(1,2), (1,5), (2,1), (2,4), (5,4), (5,6 ), (6,1), (6,3)}).

从开始到结束所有箭头都指向同一方向的路径称为有向路径。如果对于每两个节点都有一条连接它们的有向路径,则有向图是强连接的。有向图是描述二元关系的便捷方法。如果R是域D × D的二元关系,则它可以表示为标记图G = ( D , E ),其中E = {( x , y ) : xRy }。

A path in which all the arrows point in the same direction, from start to finish, is called a directed path . A directed graph is strongly connected if for every two nodes there is a directed path connecting them. Directed graphs are a convenient way to describe binary relations. If R is a binary relation with domain D × D , then it can be represented as a labeled graph G = ( D , E ), where E = {( x , y ) : xRy }.

示例0.17

Example 0.17

下面所示的有向图表示例 0.10 中的关系。

The directed graph shown below represents the relation in Example 0.10.

0.18

关系节拍图

Figure 0.18

Graph for the relation beats

文字和语言

Words and languages

单词或字符串是计算机科学的基本组成部分。定义单词的字母表可能会根据用途而变化。出于我们的目的,我们将字母表定义为非空有限集。该集合的元素是字母符号。通常,我们将使用大写希腊字母SG表示字母表,使用小写等宽字体表示字母符号。下面显示了字母表的一些示例。

Words, or sequences of characters, are the fundamental building blocks of computer science. The alphabet over which words are defined can change depending on the application. For our purposes, we define an alphabet as a nonempty finite set. The elements of this set are the symbols of the alphabet. We will usually use the uppercase Greek letters S and G to denote alphabets and lowercase monospaced fonts for the symbols of the alphabet. Several examples of alphabets are shown below.

Σ 1 = { 0 , 1 }

Σ 1 = { 0 , 1 }

Σ 2 = { a , b , c , d , e , f , g , h , i , j , k , l , m , n , o , p , q , r , s , t , u , v , w , x , y , z }

Σ 2 = { a , b , c , d , e , f , g , h , i , j , k , l , m , n , o , p , q , r , s , t , u , v , w , x , y , z }

γ = { 0 , 1 , x , y , z }

Γ = { 0 , 1 , x , y , z }

字母表上的单词(也是字母表上的字符串)是该字母表中符号的有限序列,通常一个接一个地书写,不带空格或逗号。如果Σ 1 = { 0 , 1 },则01001就是Σ 1上方的字。如果Σ 2 = { a , b , c , … , z },则abracadabra就是Σ 2上方的单词。如果w是Σ上方的一个字,则w 的长度 写为 | w |, 是它包含的符号数。长度为零的字称为空字,写为ε。空白这个词在数字系统中的作用类似于0。如果单词w的长度为n,我们可以将其写为w = w 1 w 2 ·w n,其中每个w iΣ。单词w的反转,写为w R ,是通过将w逆序书写而获得的单词(即w n w n -1 ...·w 1)。单词with是单词w的连接子串,则它是 w子词。例如, cad是abracadabra的子词。

A word over an alphabet (also a sequence over an alphabet ) is a finite sequence of symbols from that alphabet, usually written out one after the other without spaces or commas. If Σ 1 = { 0 , 1 }, then 01001 is a word over Σ 1 . If Σ 2 = { a , b , c , … , z }, then abracadabra is a word over Σ 2 . If w is a word over Σ , the length of w , written as | w | , is the number of symbols in it. A word of length zero is called the empty word and is written as ε . The empty word plays a role analogous to 0 in the numeral system. If a word w has length n , then we can write it as w = w 1 w 2 ·w n , where each w i Σ . The inversion of a word w , written as w R , is the word obtained from w by writing it in reverse order (that is, w n w n −1 …·w 1 ). A word z is a subword of w if it is a consistent subsequence of w . For example , cad is a subword of abracadabra .

如果我们有一个长度为m的单词x和一个长度为n的单词y,那么xy的串联,写作xy ,就是将单词y附加到单词x的末尾得到的单词,即单词x 1 ... x m y 1 ... y n。在一个单词与其自身多重连接的情况下,我们使用指数符号x k,意思是

If we have a word x of length m and a word y of length n , then the concatenation of x and y , written xy , is the word obtained by appending the word y to the end of the word x , that is, the word x 1 x m y 1 … y n . In the case of multiple concatenation of a word with itself, we use the exponential notation x k , meaning

k

k

xx x

xx x .

单词的词典顺序与众所周知的词典顺序相同。我们偶尔会使用修改后的词典顺序,称为Shortlex,它与词典顺序相同,只是较短的单词在较长的单词之前。因此,字母表上方所有单词的短词顺序为 { 0 , 1 }

The lexicographical order of words is identical to the well-known dictionary order. We will occasionally use a modified lexicographical order, called shortlex , which is identical to the lexicographical order except that shorter words precede longer ones. Thus, the shortlex order of all words over the alphabet { 0 , 1 } is

(ε 0、1、00、01、10、11、000... 。​

(ε, 0 , 1 , 00 , 01 , 10 , 11 , 000 , …).

如果存在一个单词z使得xz = y 我们就说单词x单词y前缀,并且如果另外xy ,则x被称为单词y的真前缀

We say that a word x is a prefix of a word y if there is a word z such that xz = y , and x is called a proper prefix of y if additionally xy .

语言是一组单词。如果一种语言中没有元素(单词)是另一个元素的正确前缀,则该语言被称为有前缀的。

A language is a set of words. A language is called prefixed if no element (word) of the language is a proper prefix of another element.

布尔逻辑

Boolean logic

布尔逻辑围绕 TRUE 和 FALSE 这两个值构建的数学系统。尽管最初是作为纯粹的数学概念而发明的,但该系统现在被视为数字电子和计算机设计的基础。 TRUE 和 FALSE 值称为布尔逻辑)值,通常表示为数值 1 和 0。我们在只有两种选择的情况下使用布尔值,例如高或低电压水平,一个可以是真或假的陈述,或者一个答案必须是或否的问题。

Boolean logic is a mathematical system built around the two values ​​TRUE and FALSE. Although originally invented as a purely mathematical concept, the system is now seen as the foundation for the design of digital electronics and computers. The values ​​TRUE and FALSE are calledBoolean values ​​and are often represented as the numeric values ​​1 and 0. We use Boolean values ​​in situations where only two possibilities are available, such as a high or low voltage level, a statement that can be true or false, or a question that must be answered yes or no.

布尔值的转换是通过布尔(逻辑)运算来完成的。最简单的布尔运算是求反,即NOT运算,用符号 Ø 表示。布尔值的负数是它的相反值。因此, Ø0 = 1 且 Ø1 = 0。合取,即AND运算,用符号标记。如果两个布尔值的值都是 1,则两个布尔值的合取为 1(真)。我们用符号∨表示替代OR运算。如果两个布尔值中的任何一个为 1,则两个布尔值的替代值为 1。此信息可以总结如下:

The transformation of boolean values ​​is done by boolean ( logical ) operations. The simplest boolean operation is negation , or the NOT operation , denoted by the symbol ¬. The negation of a boolean value is its opposite value. Thus, ¬0 = 1 and ¬1 = 0. Conjunction , or the AND operation , is denoted by the symbol . The conjunction of two boolean values ​​is equal to 1 (true), if both of these values ​​are 1. The disjunction or OR operation is denoted by the symbol . The disjunction of two boolean values ​​is equal to 1 if either of these values ​​is equal to 1. This information can be summarized as follows:

0 0 = 0

0 0 = 0

0 0 = 0

0 0 = 0

Ø0 = 1

¬0 = 1

0 1 = 0

0 1 = 0

0 1 = 1

0 1 = 1

Ø1 = 0

¬1 = 0

1 0 = 0

1 0 = 0

1 0 = 1

1 0 = 1

1 1 = 1

1 1 = 1

1 1 = 1

1 1 = 1

布尔运算用于将简单的语句组合成更复杂的布尔表达式,就像我们使用+和×算术运算来构造复杂的算术表达式一样。例如,如果P是一个布尔值,代表语句“阳光灿烂”,Q代表语句“今天是星期一”,那么我们可以写∧  Q来代表语句“”阳光明媚,今天是星期一”;∨  Q也存在类似的关系,其中“i”被“or”替代。PQ的值称为运算的操作数。

Boolean operations are used to combine simple statements into more complex Boolean expressions, much as we use the arithmetic operations + and × to construct complex arithmetic expressions. For example, if P is a Boolean value representing the truth value of the statement “The sun is shining” and Q represents the truth value of the statement “Today is Monday”, then we can write ∧  Q to represent the truth value of the statement “The sun is shining and today is Monday”; a similar relationship holds for ∨  Q , with “and” replaced by “or”. The values ​​P and Q are called the operands of the operation.

其他一些布尔运算会不时出现。( XOR ) 由符号表示,如果一个或另一个操作数的值为 1,但不是两个都为 1,则其值为1 。当两个操作数具有相同的值时,等价运算用符号编写,其值为 1。最后,用符号 → 表示的蕴涵运算,如果其第一个(左)操作数为 1 并且第二个操作数为 0,则其值为 0;在其他情况下,→ 的值为 1。我们将此信息总结如下。

A few other Boolean operations will pop up from time to time. Exclusive or , or XOR , is denoted by the symbol and has the value 1 if either one or the other operand is 1, but not both. The equivalence operation , denoted by the symbol , has the value 1 if both operands have the same value. Finally, the implication operation , denoted by the symbol → , has the value 0 if its first (left) operand is 1 and its second is 0; otherwise, → has the value 1. We summarize this information as follows.

0 0 = 0

0 0 = 0

0 0 = 1

0 0 = 1

0 → 0 = 1

0 → 0 = 1

0 1 = 1

0 1 = 1

0 1 = 0

0 1 = 0

0 → 1 = 1

0 → 1 = 1

1 0 = 1

1 0 = 1

1 0 = 0

1 0 = 0

1 → 0 = 0

1 → 0 = 0

1 1 = 0

1 1 = 0

1 1 = 1

1 1 = 1

1 → 1 = 1

1 → 1 = 1

这些操作之间存在各种依赖关系。事实上,我们只能用 AND 和 NOT 运算来表达所有布尔运算,如下所示。每行中的两个表达式是等效的。每行在左列中显示使用上述概念的操作记录,在右列中显示使用 AND 和 NOT 的等效操作。

There are various dependencies between these operations. In fact, we can express all Boolean operations only by the AND and NOT operations, as the following identities show. The two expressions in each row are equivalent. Each row presents in the left column the notation of the operation using the concepts discussed above, and in the right column the equivalent operations using AND and NOT.

P∨Q

P Q

← (← P∧ Q )

¬(¬ P ¬ Q )

QQ

PQ

P Q

¬ P Q

P Q

P Q

( PQ ) ( QP )

( PQ ) ( QP )

P Q

P Q

←( P Q )

¬( P Q )

合取和析取的分配律在转换布尔表达式时很有用。它类似于乘除加法的分配律,即a × ( b + c ) = ( a × b )+( a × c )。布尔版本有两种形式:

The distributive law of conjunction and disjunction is useful when transforming Boolean expressions. It is similar to the distributive law of multiplication over addition, which states that a × ( b + c ) = ( a × b )+( a × c ). The Boolean version comes in two forms:

  • P ( Q R ) 等于 ( P Q ) ( P R ),并且
  • P ( Q R ) is equal to ( P Q ) ( P R ), and
  • P ( Q R ) 等于 ( P Q ) ( P R )。
  • P ( Q R ) is equal to ( P Q ) ( P R ).

数学术语总结

Summary of Mathematical Terms

字母表 – 称为符号的有限、非空对象集

Alphabet – a finite, non-empty set of objects called symbols

替代方案 – 布尔 OR 运算

Alternative – Boolean operation OR

Argument – 函数的输入(数据)值

Argument – ​​input value (data) of the function

字符串——对象的有序列表

String - an ordered list of objects

循环 – 在同一顶点开始和结束的路径

Cycle – a path that starts and ends at the same vertex

补——返回不属于给定集合的所有元素的集合的操作

Complement – ​​an operation that returns a set of all elements that do not belong to a given set

树——不包含简单循环的连通图

Tree – a connected graph that does not contain any simple cycles.

双参数关系——其域是有序对集合的关系

A binary relation is a relation whose domain is the set of ordered pairs.

域——函数所有可能的输入值(参数)的集合

Domain – the set of all possible input values ​​(arguments) of a function

元素——属于集合的对象

Element – ​​an object belonging to a set

函数——将输入值转换为输出值的操作

Function – an operation that transforms input values ​​into output values

图形 – 一组点和连接这些点对的线

Graph – a set of points and lines connecting some pairs of these points.

笛卡尔积 – 集合上的运算,创建由适当集合的元素组成的所有元组的集合

Cartesian product – an operation on sets that creates the set of all tuples composed of elements of the corresponding sets.

语言——特定字母表上的一组单词

Language – a collection of words over a certain alphabet

k -tuple – k 个对象序列

k -tuple – a sequence of k objects

连接 – 布尔 AND 运算

Conjunction – Boolean operation AND

连接——组合单词的操作

Concatenation – the operation of joining words together

边 – 连接图顶点的线

Edge – a line connecting the vertices of a graph

无序对——包含两个元素的集合

An unordered pair is a set with two elements.

布尔运算——布尔值的运算

Boolean operation – operation on boolean values

谓词 – 子域为集合 {TRUE, FALSE} 的函数

Predicate – a function whose codomain is the set {TRUE, FALSE}

直线路径——没有重复顶点的路径

Simple path - a path without repeated vertices

反域——函数输出值的集合

Codomain – the set from which the output values ​​of the function come from

交集(集合的乘积)——集合上的运算,创建这些集合共有的一组元素

Intersection (product of sets) – an operation on sets that creates a set of elements common to these sets

等价关系——自反、对称和传递的双参数关系

Equivalence relation – a binary relation that is reflexive, symmetric, and transitive

关系——一个谓词,其域是一组k元组

Relation – a predicate whose domain is a set of k -tuples

单例集——单元素集

Singleton set – a set of one element

有向图 – 连接选定的这些点对的一组点和箭头(有序对)

Directed graph – a set of points and arrows (ordered pairs) connecting selected pairs of these points

连通图——包含连接任意两个顶点的路径的图

A connected graph is a graph containing paths connecting any two vertices.

集合并集——集合的一种运算,将参与集合的所有元素组合成一个集合

Union of sets – a set operation that combines all the elements of the participating sets into one set.

符号——字母表的一个元素

Symbol - an element of the alphabet

空词——长度为零的词

Empty word - a word of length zero

单词——特定字母表中符号的有限列表

Word – a finite list of symbols from a certain alphabet

路径 – 由边连接的图顶点序列

Path – a sequence of graph vertices connected by edges.

有序对 – 包含两个元素的列表,一个二元素字符串

Ordered pair – a list of two elements, a sequence of two elements

布尔值 - TRUE 或 FALSE 值,通常用 1 或 0 表示

Boolean value – TRUE or FALSE values, often represented by 1 or 0

顶点——图中的一个点

Vertex – a point in a graph

节点(或顶点)——图中的一个点

Node (also known as vertex) – a point in a graph

属性——也称为谓词

Property - otherwise known as predicate

空集——没有元素的集合

Empty set – a set that has no elements.

集合——一组对象

Set – a group of objects

0.3

定义、定理和证明

0.3

Definitions, Theorems and Proofs

定理和证明是数学的身体和血液,定义是数学的灵魂。这三个实体构成了数学每个分支的基础,包括我们的数学分支。

Theorems and proofs are the body and blood of mathematics, and definitions are its soul. These three entities form the basis of every branch of mathematics, including our own.

定义描述了我们使用的对象和概念。该定义可以很简单,如本章前面介绍的集合的定义,也可以很复杂,如密码系统中安全性的定义。任何数学定义的基本特征都是精确性。当我们定义一个对象时,我们必须确保清楚什么定义了该对象,什么不定义该对象。

Definitions describe the objects and concepts we use. A definition can be simple, as in the case of the definition of a set presented earlier in this chapter, or complex, as in the definition of security in a cryptographic system. The essential feature of any mathematical definition is precision. When we define an object, we must ensure that we are unambiguous about what the object defines and what it does not.

在定义了各种对象和概念之后,我们通常会制定关于它们的数学句子 (陈述)。典型的说法是某个对象具有某种属性。陈述可能真实,也可能不真实;然而,就像定义一样,它必须是精确的。不允许对其含义存在任何不确定性。

After defining various objects and concepts, we usually formulate mathematical sentences (statements) about them. A typical statement is that a certain object has a certain property. The statement may be true or false; but again like a definition, it must be precise. No uncertainty about its meaning is permitted.

证明是证明特定陈述正确的令人信服的逻辑论证。在数学中,这个论证必须是严格的。换句话说,它必须在绝对意义上具有说服力。在日常生活或法律中,证据的标准较低。在谋杀案审判中,需要“排除合理怀疑”的证据。证据的分量(证词或重要事实)可以说服陪审团认定被告无罪或有罪。然而,这样的证据在数学证明中不起任何作用。数学家要求毫无疑问的证明。

A proof is a convincing logical argument that a given statement is true. In mathematics, the argument must be rigorous; in other words, it must be convincing in an absolute sense. In everyday life or in law, the standard of proof is lower. In a murder trial, proof "beyond a reasonable doubt" is required. The weight of the evidence (or testimony or material fact) can persuade a jury to find the accused innocent or guilty. But such evidence plays no role in a mathematical proof. The mathematician demands proof beyond a reasonable doubt.

定理是已被证明正确的数学陈述。一般来说,我们保留在具有特殊含义的句子中使用这个词。我们有时会证明一些有趣的陈述,只是因为它们有助于证明其他更重要的陈述。这些类型的句子称为引理。有时,一个陈述或其证明可以很容易地推断出其他相关陈述是正确的。这样的命题称为定理的结论。

A theorem is a mathematical statement that has been proven to be true. In general, we reserve the use of this word for statements of special importance. Occasionally, we prove statements that are interesting only because they help us prove other, more significant statements. Such statements are called lemmas . Sometimes it happens that a theorem or its proof allows us to easily deduce that other related statements are true. Such statements are called corollaries of the theorem.

寻找证据

Finding evidence

确定数学陈述真假的唯一方法是进行数学证明。不幸的是,找到证据并不总是那么容易。这项任务不能简化为一组简单的规则或程序。在阅读本手册时,读者经常需要提供各种定理的证明。不过,无需提前担心!虽然没有人找到创建证据的通用公式,但有一些通用策略可以提供帮助。

The only way to determine whether a mathematical statement is true or false is to perform a mathematical proof. Unfortunately, finding a proof is not always easy. The task cannot be reduced to a simple set of rules or procedures. In the course of working through this manual, the reader will often have to provide proofs of various theorems. But do not worry in advance! Although no one has found a universal recipe for creating proofs, there are several general strategies that can help.

你应该仔细阅读你想要证明的陈述。我们真的理解所有的符号吗?值得用你自己的话重写这句话。将它们分成几部分并分别考虑。

You should carefully read the sentence you want to prove. Do you really understand the entire notation? It's worth rewriting the sentence in your own words. Divide it into parts and consider each of them separately.

有时复合句的某些部分并不是立即显而易见的。一种常见的复合句的形式是“ P if and only if Q ”,其中PQ是数学句子。该符号是由两部分组成的句子的缩写。第一部分是“ P only if Q ,意思是:如果P为真,则Q也为真,我们写为P⇒Q 第二部分是“ P if Q ”,意思是:如果Q为真,则P也为真,写PÜQ 这些部分中的第一部分是朝着原始陈述的一个方向,第二部分是朝着另一个方向。 “P 当且仅当Q ”写为P Q。为了证明这种形式的定理,需要在两个方向上进行证明。通常这些方向之一比另一个更容易证明。

Sometimes the parts of a compound sentence are not immediately obvious. One common compound sentence is of the form " P if and only if Q ," where P and Q are mathematical sentences. This notation is shorthand for a two-part sentence. The first part is " P only if Q ," meaning: if P is true, then Q is true, written as P Q . The second part is " P , if Q ," meaning: if Q is true, then P is true, written as P Ü Q . The first part of this statement is in one direction of the original statement, while the second part is in the other direction . "P if and only if Q " is written as P Q . To prove a statement of this form, it is necessary to prove it in both directions. Often, one of these directions is easier to prove than the other.

另一种类型的复杂句子是陈述两个集合A和 B相等。第一部分声明A是B的子集,第二部分声明B是A的子集。因此,证明A = B 的一种常见方法是证明A 的每个元素也是B的元素,然后B的每个元素也是A的元素。

Another type of compound proposition is the statement that two sets A and  B are equal. The first part states that A is a subset of B , and the second part states that B is a subset of A . Hence, one common way of proving that A = B is to show that every element of A is also an element of B , and then that every element of B is also an element of A .

最后,当试图证明一个命题或命题的一部分时,必须尝试获得一种直观的“内在”感觉,了解为什么它应该是正确的。尝试示例在这里特别有帮助。如果一个命题指出某种类型的所有对象都具有某种属性,那么我们可以选择该类型的多个对象并检查它们是否确实具有该属性。下一步,你可以尝试找到一个不满足这个条件的对象,这称为反例。如果这种说法确实正确,我们将找不到反例。尝试寻找反例时看到困难出现在哪里可以帮助您理解为什么这个陈述是正确的。

Finally, when we try to prove a statement, or part of a statement, we try to get an intuitive “inner” sense of why it should be true. Experimenting with examples can be particularly helpful here. If the statement states that all objects of a certain type have a certain property, we can pick a few objects of that type and see if they really do have that property. The next step is to try to find an object that doesn’t satisfy that condition, which we call a counterexample . If the statement is really true, we won’t be able to find a counterexample. Seeing where the difficulties in trying to find a counterexample arise can help us understand why the statement is true.

示例 0.19

Example 0.19

假设我们要证明对于任意图G,该图所有顶点的度数之和为偶数

Suppose we want to prove the statement that for any graph G, the sum of the degrees of all the vertices of that graph is an even number .

首先,我们选择一些图表并在实际中测试此语句。下面是两个例子:

First, we select a few graphs and test this statement in action. Here are two examples:

然后我们尝试寻找一个反例;换句话说,我们正在寻找一个图,其中该总和为奇数。

Then we try to find a counterexample; in other words, we look for a graph in which this sum is an odd number.

我们是否已经看出这个说法是正确的,我们如何证明它?

Can you already see that this statement is true, and how can you prove it?

如果我们不断地试图证明一个陈述,那么值得尝试一些更简单的事情。人们可以尝试证明该陈述的一种特殊情况。例如,如果我们试图证明某个属性对于所有k > 0 都成立,我们首先尝试在k = 1时证明它。如果成功,我们会尝试k = 2,依此类推,直到我们捕获更多一般情况。如果所选择的特例难以证明,则可以尝试另一个特例,甚至可能是该特例的一个特例。

If we get stuck trying to prove a statement, it's worth trying something easier. We can try to prove a special case of the statement. For example, if we're trying to prove that some property is true for all k > 0, we first try to prove it for k = 1. If that works, we try for k = 2, and so on, until we get a more general case. If the chosen special case turns out to be hard to prove, we can try another special case, or perhaps even a special case of that special case.

最后,当我们确信已经找到证据时,我们需要适当地记录下来。一个写得很好的证明是一系列句子,每个句子都是从前面的句子中进行简单推理得出的。仔细写下证明对于帮助读者理解并确保其没有错误非常重要。

Finally, when we are sure that we have found a proof, we need to write it down properly. A well-written proof is a series of statements, each of which follows by simple reasoning from the previous statements. Writing a proof carefully is important both because it helps the reader understand it and because it helps us to make sure that it is free from errors.

以下是一些可以帮助您创建良好证据的提示。

Here are some tips to help you create good evidence.

  • 要有耐心。寻找证据需要时间。如果您没有立即明白如何证明某件事,请不要担心。研究人员有时会花数周甚至数年的时间研究单个证据。
  • Be patient . Finding evidence takes time. If you don't immediately see how to prove something, don't worry. Researchers sometimes work for weeks or even years on a single piece of evidence.
  • 一段时间后回来继续任务。看看你想要证明的陈述,想一想,然后离开,几分钟或几小时后再回来。让你头脑中无意识的直觉部分有机会发挥作用。
  • Return to the task after some time . Look at the statement you want to prove, think about it for a while, leave it, then return a few minutes or hours later. Give the unconscious intuitive part of your mind a chance to work.
  • 保持整洁。当你对想要证明的命题建立直觉时,请使用简单、清晰的绘图和注释。你想要深入了解问题的本质,而马虎会阻碍这一点。此外,当你编写一个解决方案供其他人阅读时,整洁也会帮助他们理解它。
  • Be neat . When you're building an intuition about a proposition you want to prove, use simple, clear drawings and notes. You want to create insight into the nature of the problem, and sloppiness gets in the way of that. Moreover, when you're writing a solution for someone else to read, neatness will help that person understand it, too.
  • 保持简洁。这可以帮助您表达重要的想法,而不会陷入细节之中。良好的数学符号可以帮助您简洁地表达想法。但是,您需要确保在编写证明时,足够详细地表达您的推理,以便读者能够快速理解您想要说的内容。
  • Be concise . This helps you express important ideas without getting bogged down in details. Good mathematical notation helps you to express ideas concisely. However, you need to take care when writing a proof to present your reasoning in enough detail that the reader can quickly understand what you are trying to say.

作为练习,我们将证明德摩根定律之一。

As an exercise, we will prove one of DeMorgan's laws.

定理 0.20

Theorem 0.20

对于任意两个集合A和 BA B = A B。

For any two sets A and  B , A B = A B .

首先,这句话的意思清楚吗?如果您不明白符号或顶部破折号的含义,请参阅第 4 页的讨论。

First, is the meaning of this statement clear? If you don't understand the meaning of the symbols or , or the dash at the top, see the discussion on page 4.

为了证明这个定理,我们需要证明集合A BA B相等。回想一下,我们可以通过证明一个集合的每个元素也是另一个集合的元素来证明集合的相等性,反之亦然。在阅读下面的证明之前,请考虑几个例子,然后尝试自己进行证明。

To prove this theorem, we need to show that the sets A B and A B are equal. Recall that we can prove set equality by showing that every element of one set is also an element of the other set, and vice versa. Before reading the proof that follows, it is worth considering a few examples and then trying the proof yourself.

证明该定理指出两个集合A BA B相等。我们将通过证明一个集合中的每个元素也是另一个集合中的元素来证明这一论点,反之亦然。

Proof This theorem states that two sets, A B and A B , are equal. We prove this theorem by showing that every element of one of the sets is also an element of the other, and vice versa.

假设x是集合A È B的一个元素。根据集合补集 的定义,x不属于A B。因此,根据集合和的定义,x既不A的元素,也不是B的元素。换句话说,x属于A,  x属于B。因此,根据集合交集的定义,我们得到x属于A∩B

Suppose x is an element of the set A È B . By the definition of the complement of sets, it follows that x is not an element of A B . Therefore, by the definition of the union of sets, x is neither an element of A nor an element of B . In other words, x belongs to A and  x belongs to B . Hence, by the definition of set intersection, we have that x belongs to A B .

为了反方向证明该定理,假设x属于A B。这意味着x既属于A又属于B。由此可见x不属于Ax不属于B,因此不属于这些集合的和。因此x属于这些集合之和的补集;换句话说,x属于A∪B 这就完成了定理的证明。  

To prove the theorem in the opposite direction, suppose x belongs to A B . This means that x belongs to both A and B . It follows that x does not belong to A and that x does not belong to B , and hence does not belong to the union of these sets. Hence x belongs to the complement of the union of these sets; in other words, x belongs to A B , which completes the proof of the theorem.  

现在让我们证明例 0.19 中的陈述。

Let us now prove the statement from Example 0.19.

定理 0.21

Theorem 0.21

对于任意图G,G中所有顶点的度数之和为偶数。

For any graph G, the sum of the degrees of all the vertices of G is an even number.

证明G 中的每条边都连接到两个顶点。每条边为其所连接的每个顶点的度贡献 1。因此,每条边将所有节点的度数之和加 2。因此,如果G包含e条边,则G所有顶点的度数之和为 2e为偶数。

Proof Each edge in G is connected to two vertices. Each edge contributes 1 to the degree of each vertex to which it is connected. Thus, each edge contributes 2 to the sum of the degrees of all the nodes. Therefore, if G contains e edges, then the sum of the degrees of all the vertices of G is 2e , which is an even number.

0.4

证据类型

0.4

Types of evidence

数学证明中经常出现几种类型的论证。在这里,我们将描述计算理论中经常出现的一些内容。请注意,一个证明可以包含不止一种类型的论证,因为一个证明可以有多个不同的子证据。

Several types of arguments often appear in mathematical proofs. Here we describe several that are common in the theory of computation. Note that a proof may contain more than one type of argument, since a proof may have several different subproofs.

构造证明

Proof by construction

许多主张声称存在某种类型的物体。证明该定理的一种方法是演示如何构造这样的对象。这种技术称为构造证明(constructionproof)。

Many theorems state that a certain type of object exists. One way to prove such a theorem is to demonstrate how to construct such an object. This technique is called proof by construction .

让我们尝试使用构造证明来证明以下定理。如果图的每个顶点都有度k ,我们将图定义为k-正则图。

Let us try to use proof by construction to prove the following theorem. A graph is defined as k-regular if every vertex of the graph has degree k .

定理 0.22

Theorem 0.22

对于每个大于 2 的偶数n,都有一个具有n 个顶点的 3-正则图。

For every even number n greater than 2, there is a 3-regular graph with n vertices.

证明n为大于2的偶数。我们根据以下过程构造一个具有n个 顶点的图G = ( V , E ) :顶点集GV = {0, 1, …, n − 1} ,并且边集G被设置

Proof Let n be an even number greater than 2. We construct a graph G = ( V , E ) with vertices according to the following procedure: the set of vertices of G is V = {0, 1, …, n − 1}, and the set of edges of G is the set

E = { { i , i + 1} :对于 0 ≤ in − 2} { { n − 1, 0} } { { i , i + n /2} :对于 0 ≤ in /2 − 1}。

E = { { i , i + 1} : for 0 ≤ in − 2} { { n − 1, 0} } { { i , i + n /2} : for 0 ≤ in /2 − 1}.

该图的顶点可以通过将它们均匀分布在圆上来表示。在这种情况下,由集合E的定义的顶线描述的边连接圆周围的相邻顶点对。集合E定义的底线中描述的边在圆另一侧的顶点之间延伸。这个心理图像清楚地表明G的每个顶点的度数都是 3。

The vertices of this graph can be represented by distributing them evenly on a circle. In this case, the edges described by the top line of the definition of set E connect adjacent pairs of vertices around the circle. The edges described by the bottom line of the definition of set E run between vertices on the opposite side of the circle. This mental picture clearly shows that each vertex of G has degree 3.

间接证明(通过减少矛盾)

Proof by contradiction (reduction to contradiction)

证明定理的另一种常见论证形式包括假设该定理是错误的,然后表明该假设显然会导致错误的结论,称为矛盾。我们在日常生活中经常使用这种推理,如下例所示。

Another common form of argument in proving a theorem involves assuming that the theorem is false and then showing that this assumption leads to an obviously false conclusion, called a contradiction. We use this type of reasoning frequently in everyday life, as in the following example.

示例 0.23

Example 0.23

杰克看到吉尔刚才还在外面。她发现自己没有被淋湿,所以她知道没有下雨。他证明没有下雨的“证据”是,如果下雨(该断言是错误的),吉尔就会被淋湿(显然是错误的效果)。因此不能下雨。

Jack sees Jill, who has just been outside. He notices that she is not wet, so he knows that it is not raining. His "proof" that it is not raining is that if it were raining (the false assumption that the statement is false), Jill would get wet (an obviously false consequence). Therefore, it cannot be raining.

现在我们尝试间接证明2的平方根是一个无理数。如果一个数是分数m / n ,则该数是有理数,其中mn是整数;换句话说,有理数是整数mn的商。例如,2/3显然是一个有理数。如果一个数不是有理数,则该数称为无理数。

Now let's try to prove indirectly that the square root of 2 is an irrational number. A number is rational if it is a fraction m / n , where m and n are integers; in other words, a rational number is the quotient of integers m and n . For example, 2/3 is obviously a rational number. A number is called irrational if it is not rational.

定理 0.24

Theorem 0.24

√2是无理

2 is an irrational number.

证明 为了证明的目的,我们隐含地假设2是有理数。意思是

Proof For the purpose of the proof indirectly, we assume that2 is a rational number. Therefore,

,

,

其中mn是整数。如果数字mn都可以被同一个大于 1 的整数整除,则我们将它们除以最大的此类数字(减少分数)。此操作不会更改分数的值。因此,数字mn中至少有一个必须是奇数。

where m and n are integers. If both numbers m and n are divisible by the same integer greater than 1, we divide both by the largest such number (we reduce the fraction). This operation does not change the value of the fraction. As a result, at least one of the numbers m and n must be an odd number.

我们将方程两边同时乘以n,得到

We multiply both sides of the equation by n and get

n 2 = m

n 2 = m .

我们将两边平方并得到

We square both sides and get

2 n 2 = m 2

2 n 2 = m 2 .

由于m 2是整数n 2 的两倍,所以我们知道m 2是偶数。因此m本身也是偶数,因为奇数的平方总是奇数。因此我们可以写成m = 2 k,其中k是某个整数。用2 k代替m,我们得到

Since m 2 is a double of the integer n 2 , we know that m 2 is an even number. Therefore m itself is also even, since the square of an odd number is always odd. We can therefore write m = 2 k , where k is some integer. Substituting 2 k for m , we get

2 n 2 = (2 k ) 2

2n2 = ( 2k ) 2

= 4k 2

= 4k2 .

两边同时除以 2,我们得到

Dividing both sides by 2, we get

n 2 = 2 k 2

n 2 = 2 k 2 .

然而,该结果表明n 2是偶数,因此n是偶数。因此我们证明mn都是偶数。然而,我们之前已经减少了mn(减少了分数),因此两者不能同时为偶数 - 这是一个矛盾。

However, this result shows that n 2 is even, and therefore n is even. We have therefore shown that both m and n are even. However, we have previously reduced m and n (reduced the fraction), so both cannot be even at the same time – a contradiction.

感应证明

Inductive proof

归纳证明是一种先进的方法,用于证明某个无限集合的所有元素都具有特定的属性。例如,我们可以使用归纳证明来证明某个算术表达式对于每个变量赋值都计算出所需的值,或者程序在所有步骤或所有输入值中都能正确运行。

An inductive proof is an advanced method for showing that all elements of an infinite set have a certain property. For example, we can use an inductive proof to show that a certain arithmetic expression evaluates to the desired value for every variable assignment, or that a program executes correctly at all steps or for all input values.

为了说明归纳证明是如何工作的,让我们假设一个无限集合作为自然数集合N = {1, 2, 3, …},我们将所研究的属性称为P。我们的目标是证明P ( k ) 对于每个自然数k都成立。换句话说,我们要证明P (1) 为真,就像P (2)、P (3)、P (4) 等等一样。

To illustrate how the inductive proof works, let us take the infinite set to be the set of natural numbers N = {1, 2, 3, …}, and call the property in question P . Our goal is to show that P ( k ) is true for every natural number k . In other words, we want to prove that P (1) is true, as are P (2), P (3), P (4), and so on.

每个归纳证明都由两部分组成,基本步骤归纳基础)和归纳步骤。这些部分中的每一个都是一个单独的证据。在基本步骤中,我们证明P (1)为真。归纳步骤证明,对于每个i ≥ 1,如果P ( i ) 为真,则P ( i + 1)也为真。

Every inductive proof consists of two parts, a basic step ( induction basis ) and an inductive step . Each of these parts is an individual proof. In the basic step, we prove that P (1) is true. The inductive step proves that for all i ≥ 1, if P ( i ) is true, then P ( i + 1) is also true .

证明这两部分后,我们得到了期望的结果 - 具体来说,P ( i ) 对于所有i都成立。为什么?首先,我们知道P (1) 为真,因为我们在基本步骤中证明了它。其次,我们知道P (2) 为真,因为归纳步骤证明,如果P (1) 为真,则P (2) 为真,并且我们已经知道P (1) 为真。第三,我们知道P (3)为真,因为归纳步骤证明如果P (2)为真,则P (3)为真,并且我们已经知道P (2)为真。我们对所有自然数继续这个过程,证明P (4) 为真,P (5) 为真,依此类推。

After proving both parts, we get the desired result—namely, that P ( i ) is true for all i . Why? First, we know that P (1) is true, since we proved it in the basic step. Second, we know that P (2) is true, since the inductive step proves that if P (1) is true, then P (2) is true, and we already know that P (1) is true. Third, we know that P (3) is true, since the inductive step proves that if P (2) is true, then P (3) is true, and we already know that P (2) is true. We continue this process for all natural numbers, showing that P (4) is true, P (5) is true, and so on.

一旦理解了上一段,您就可以轻松应用此方法的变体和概括。例如,基本步骤不一定要从 1 开始;我们可以从b的任何值开始。在这种情况下,归纳证明将表明P ( k ) 对于任何不小于b 的k都成立。

Once the previous paragraph is understood, variations and generalizations of this method can be easily applied. For example, the basic step does not necessarily have to start at 1; we can start at any value b . In that case, an inductive proof will show that P ( k ) is true for all k not less than b .

在归纳步骤中, P ( i )为真的假设称为归纳假设inductor suggest)。有时,使用更强的归纳假设来说明P ( j ) 对于所有ji都成立是有用的。归纳证明仍然有效,因为当我们想要证明P ( i + 1) 为真时,我们已经证明P ( j ) 对于每个ji都为真。

In the inductive step, the assumption that P ( i ) is true is called the inductive hypothesis ( inductive assumption ). It is sometimes useful to use a stronger inductive hypothesis stating that P ( j ) is true for all ji . The inductive proof will still work, since when we want to show that P ( i + 1) is true, we have already proven that P ( j ) is true for all ji .

归纳证明的书写格式如下:

The format for writing inductive proofs is as follows:

基本步骤:我们证明P (1)为真。

Basic Step : We prove that P (1) is true.

归纳步骤:对于每个i≥1,我们假设P ( i )为真,然后用这个假设来证明P ( i +1)为真。

Inductive Step : For each i ≥ 1, we assume that P ( i ) is true, and then use this assumption to show that P ( i + 1) is true.

现在我们将通过归纳证明用于计算每月抵押贷款分期付款的公式是正确的。买房时,许多人会借入部分购房所需资金,然后在一定期限内偿还债务。还款条款规定每月支付固定金额以支付利息以及部分原始金额,以便在例如 30 年内偿还全部金额。每月还款额的计算公式虽然神秘,但其实很简单。它涉及很多人的日常事务,所以应该很有趣。我们将使用归纳法来证明其正确性,这将为该技术提供一个很好的说明。

We will now prove by induction the correctness of the formula used to calculate the monthly payments on mortgages. When buying a house, many people borrow part of the money needed to make the purchase and then repay the debt over a specified number of years. The repayment terms call for a fixed amount to be paid each month to cover interest as well as part of the original amount, so that the total is paid back in, say, 30 years. The formula for calculating the monthly payments is shrouded in mystery, but it is actually quite simple. It concerns many people's daily lives, so it should be interesting. We will use induction to prove its correctness, which will provide a good illustration of the technique.

首先,我们将定义几个变量的名称和含义。令P资本,即原始贷款的总和。设I > 0 为贷款年利率,其中I = 0.06 表示利率为 6%。令Y为每月分期付款。为了方便起见,我们将使用I来定义变量M,即每月乘数。这是您的贷款每月因应计利息而变化的利率。根据标准银行惯例,月利率为年利率的十二分之一,即M = 1 + I /12,利息按月计息(按月复利)。

First, let’s define the names and meanings of a few variables. Let P be the principal , or the amount of the original loan. Let I > 0 be the annual percentage rate of the loan, where I = 0.06 means an interest rate of 6%. Let Y be the monthly payment. For convenience, we will use I to define the variable M , or the monthly multiplier. This is the rate of change in the loan each month due to interest accrual. In accordance with standard banking practice, the monthly interest rate is one-twelfth of the annual rate, or M = 1 + I /12, and interest is compounded monthly (monthly compounding).

每个月都会发生两件事。首先,由于每月乘数,贷款规模往往会增加。其次,该金额由于每月还款而减少。令P t为第 t个月后剩余待偿还的贷款金额。按照这个惯例,P 0 = P 是原始贷款,P 1  =  MP 0  −  Y是一个月后的贷款金额,P 2 = MP 1Y是两个月后的贷款金额。现在我们准备通过t 的归纳来制定和证明一个定理,给出P t值的公式。

Each month, two things happen. First, the size of the loan tends to increase because of the monthly multiplier. Second, the size of the loan tends to decrease because of the monthly payment. Let P t be the size of the loan remaining to be paid after the tth month. With this convention, P 0 = P is the original loan, P 1  =  MP 0  −  Y is the size of the loan after one month, and P 2 = MP 1Y is the size of the loan after two months. We are now ready to state and prove by induction on t the theorem that gives a formula for the values ​​of P t .

定理 0.25

Theorem 0.25

对于每个t ≥ 0 都成立

For every t ≥ 0 it holds

证据

Evidence

基本步骤:我们证明该公式对于t = 0 有效。如果t = 0,则该公式变为

Basic Step : We prove that the formula is valid for t = 0. If t = 0, then the formula takes the form

右边可以通过注意到M 0 = 1 来简化。因此我们得到

The right-hand side can be simplified by noting that M 0 = 1. We thus obtain

P 0 = P ,

P 0 = P ,

这是正确的,因为我们已将P 0定义为P。这样我们就证明了归纳法的基本步骤是满足的。

which is true since we defined P 0 as P . We have thus proved that the fundamental step of induction is satisfied.

归纳步骤:对于每个k ≥ 0,我们假设如果公式对于t = k成立,那么它对于t = k + 1 成立。归纳假设指出:

Inductive step : For each k ≥ 0, we assume that if the formula holds for t = k , then it follows that it holds for t = k + 1. The inductive hypothesis states that

我们的目标是证明

Our goal is to prove that

我们将通过以下步骤来完成此任务。由于P k +1是根据P k定义的,我们知道

We will do this in the following steps. Since P k +1 is defined in terms of P k , we know that

P k +1 = P k MY

P k +1 = P k MY .

因此,使用归纳假设计算P k,我们得到

Thus, using the induction hypothesis to calculate P k , we get

乘以M并变换Y后我们得到

After multiplying by M and transforming Y we get

因此,公式对于t = k +1是正确的,从而完成了定理的证明。

Thus, the formula is valid for t = k + 1, which completes the proof of the theorem.

在问题0.15中,使用上述公式计算当前的贷款分期付款。

In task 0.15, use the above formula to calculate the current loan installments.

练习

Exercises

0.1 检查以下集合的形式表示,以了解它们包含哪些元素。对于每个集合,用日常语言写一个简短的非正式描述。

0.1 Examine the following formal representations of sets to understand what elements they contain. For each set, write a short informal description in everyday language.

{1, 3, 5, 7, … }

a. {1, 3, 5, 7, …}

b. {…,−4,−2, 0, 2, 4, …}

b. {…,−4,−2, 0, 2, 4, …}

c. { n : n = 2 m对于属于N的某个m }

c. { n : n = 2 m for some m belonging to N }

d. { n :对于属于N的某个m , n = 2 m,对于N中的某个k , n = 3 k }

d. { n : n = 2 m for some m belonging to N , and n = 3 k for some k from N }

e. { w : w是由 0 和 1 组成的单词,w等于反转的w }

e. { w : w is a word made up of zeros and ones and w is equal to w reversed }

f. { n : n是整数且n = n + 1}

f. { n : n is an integer and n = n + 1}

0.2 写出下列集合的正式定义。

0.2 Write formal definitions of the following sets.

a. 包含数字 1、10 和 100 的集合

a. The set containing the numbers 1, 10 and 100

b. 包含所有大于 5 的整数的集合

b. The set containing all integers greater than 5

c. 包含所有小于 5 的自然数的集合

c. The set containing all natural numbers less than 5

d. 包含单词 aba 的集合

d. A set containing the word aba

e. 包含空词的集合

e. A set containing an empty word

f. 不包含任何内容的集合

f. A set that contains nothing

0.3A为集合 { x , y , z } ,B为集合 { x , y } 。

0.3 Let A be the set { x , y , z}, and B be the set { x , y }.

AB子集吗?

a. Is A a subset of B ?

b. BA的子集吗?

b. Is B a subset of A ?

C. A B 是什么?

c. What is A B ?

d. A B 是什么?

d. What is A B ?

e. 什么是A × B

e. What is A × B ?

f. B 的幂集是多少?

f. What is the power set of set B ?

0.4 如果 A 有a 个元素,Bb 个元素,则A × B包含多少个元素?证明你的答案合理。

0.4 If A contains a elements and B has b elements, how many elements will A × B contain ? Justify your answer.

0.5 如果C是一个有c个元素的集合,那么C的幂集包含多少个元素?证明你的答案合理。

0.5 If C is a set with c elements, how many elements does the power set of C contain ? Justify your answer.

0.6X为集合 {1, 2, 3, 4, 5},Y为集合 {6, 7, 8, 9, 10}。一元函数f : XY和二元函数g : X × YY如下表所示。

0.6 Let X be the set {1, 2, 3, 4, 5} and Y be the set {6, 7, 8, 9, 10}. The unary function f : XY and the binary function g : X × YY are described by the following tables.

n

n

f ( n )

f ( n )

G

g

6

6

7

7

8

8

9

9

10

10

1

1

6

6

1

1

10

10

10

10

10

10

10

10

10

10

2

2

7

7

2

2

7

7

8

8

9

9

10

10

6

6

3

3

6

6

3

3

7

7

7

7

8

8

8

8

9

9

4

4

7

7

4

4

9

9

8

8

7

7

6

6

10

10

5

5

6

6

5

5

6

6

6

6

6

6

6

6

6

6

f (2) 的值是多少

a. What is the value of f (2)?

b. f 的域和子域是什么?

b. What is the domain and codomain of f ?

c. g (2, 10) 的值是多少?

c. What is the value of g (2, 10)?

d. g 的域和子域是什么?

d. What is the domain and codomain of g ?

e.g (4, f (4)) 的值是多少

e. What is the value of g (4, f (4))?

0.7 对于每个点,给出满足给定条件的关系的示例。

0.7 For each point, give an example of a relation that satisfies the given condition.

a. 自反且对称,但不及物

a. Reflexive and symmetric, but not transitive

b. 自反和及物,但不对称

b. Reflexive and transitive, but not symmetric

c. 对称且传递,但不自反

c. Symmetric and transitive, but not reflexive

0.8 考虑一个无向图 = ( VE ),其中V是顶点集,是 {1, 2, 3, 4},E是边集,是 {{1, 2}, {2, 3} 、{1, 3}、{2, 4}、{1, 4}}。画出图形G。每个顶点的度数是多少?在图G的图中,标记从顶点 3 到顶点 4 的路径。

0.8 Consider an undirected graph = ( VE ), where V , the set of vertices, is {1, 2, 3, 4} and E , the set of edges, is {{1, 2}, {2, 3}, {1, 3}, {2, 4}, {1, 4}}. Draw the graph G . What is the degree of each vertex? On the drawing of G, mark the path from vertex 3 to vertex 4.

0.9 写出下图的正式描述。

0.9 Write a formal description of the graph below.

任务

Tasks

0.10 找出下面证明中 2 = 1 的错误。

0.10 Find the error in the proof below that 2 = 1.

考虑等式a = b。我们将等式两边乘以a,得到a 2 = ab。我们将等式两边减去b 2,得到a 2b 2 = abb 2。我们将两边重新排列为 ( a + b )( ab ) = b ( ab ),然后将两边除以 ( ab ),得到a + b = b。最后,我们用 1 代替a和 b,得到 2 = 1。

Consider the equation a = b . We multiply both sides of the equation by a , getting a 2 = ab . We subtract b 2 from both sides of the equation , getting a 2b 2 = abb 2 . We transform both sides to the form ( a + b )( ab ) = b ( ab ), and then divide both sides by ( ab ), getting a + b = b . Finally, we substitute 1 for a and  b , which gives 2 = 1.

0.11S ( n ) = 1 + 2 + + n为前n 个自然数的和,令C ( n ) = 1 3 + 2 3 + + n 3为前n 个自然数的立方和自然数。使用n的归纳法证明以下等式,得出令人惊讶的结论:对于每个n , C ( n ) = S2 ( n ) 。

0.11 Let S ( n ) = 1 + 2 + + n be the sum of the first n natural numbers, and let C ( n ) = 1 3 + 2 3 + + n 3 be the sum of the first n cubes of the natural numbers. Prove the following equalities using induction on n to reach the surprising conclusion that C ( n ) = S 2 ( n ) for all n .

S ( n ) = 1 / 3 n ( n + 1)

a. S ( n ) = 1 / 3 n ( n + 1).

b. C ( n ) = 1 / 3 ( n 4 + 2 n 3 + n 2 ) = 1 / 3 n 2 ( n + 1) 2

b. C ( n ) = 1 / 3 ( n 4 + 2 n 3 + n 2 ) = 1 / 3 n 2 ( n + 1) 2 .

0.12 找出以下证明中所有马颜色相同的错误。

0.12 Find the error in the proof below that all horses are the same color.

定理:在任何一组h的马中,所有马的颜色都是相同的。

Theorem : In any set h of horses, all the horses are the same color.

证明:通过h归纳。

Proof : By induction on h .

基本步骤:对于h = 1。在任何仅包含一匹马的集合中,所有马显然都具有相同的颜色。

Basic step : For h = 1. In any set containing only one horse, all horses obviously have the same color.

归纳步骤:对于k ≥ 1,我们假设该命题对于h = k成立,并证明对于h = k +1也成立包含k +1 匹马集合H。我们将证明这组中的所有马都是相同的颜色。仅包含k匹马的集合H 1。根据归纳假设,集合H 1中的所有马都是相同颜色的。现在我们返回移除的马并移除另一匹以获得集合H 2。同样的道理, H 2中的所有马都是相同的颜色。因此,集合中的所有马必须具有相同的颜色,这就完成了证明。

Inductive Step : For k ≥ 1, we assume that the thesis is true for h = k and we will show that it is also true for h = k + 1. Take any set H containing k + 1 horses. We will show that all horses in this set are of the same color. We remove one horse from this set to obtain a set H 1 containing only k horses. By the inductive assumption, all horses in H 1 are of the same color. Now we return the removed horse and remove another one to obtain the set H 2 . By the same reasoning, all horses in H 2 are of the same color. Therefore, all horses in the set must have the same color, which completes the proof.

0.13 证明任何具有两个或多个顶点的无环图都包含两个等度的顶点。

0.13 Prove that every loop-free graph with two or more vertices contains two vertices of equal degree.

A* 0.14 拉姆齐定理。设G是一个图。 G中的是一个子图,其中每两个顶点由一条边连接。 Anticlique,也称为独立集,是其中任何两个顶点都没有边连接的子图。证明每个具有n 个顶点的图都包含一些或一个至少具有1/3 log 2 n 个顶点的反派。

A* 0.14 Ramsey's Theorem . Let G be a graph. A clique in G is a subgraph in which every two vertices are connected by an edge. An anticlique , also called an independent set , is a subgraph in which any two vertices are not connected by an edge. Prove that every graph with n vertices contains either some or an anticlique with at least 1 / 3 log 2 n vertices.

A 0.15利用定理0.25推导出根据贷款价值P、利率I和还款次数 t 计算每月贷款还款额的公式。假设还款t次后,债务金额减少到 0。使用此公式计算 30 年期贷款、每月还款 360 次、初始贷款价值 100,000 美元、年利率 5% 的每月还款额。

A 0.15 Use Theorem 0.25 to derive a formula for calculating the monthly payment for a loan from the loan amount P , the interest rate I , and the number of payments  t . Assume that after making t payments, the amount owed is reduced to 0. Use this formula to calculate the monthly payment for a 30-year loan with 360 monthly payments for an initial loan amount of $100,000 at an annual interest rate of 5%.

精选解决方案

Selected solutions

0.14 为两堆顶点准备空间:A和 B。然后逐一考虑所有顶点,如果给定顶点 x 的度数大于尚未考虑的顶点的一半,则将其放入A堆,否则放入B堆;如果x被放置在A堆中( B堆中),则从图中删除 x 未连接的所有顶点。执行这些操作直到考虑或删除所有顶点。我们在每个步骤中删除不超过一半的顶点,因此我们将至少采取 log 2n步骤。在每一步中,都会将一个顶点添加到其中一个堆中,因此其中一个堆的大小至少为1 / 3 log 2 n顶点。堆 A包含形成团的顶点,堆B包含形成反团的顶点。

0.14 Prepare space for two piles of vertices: A and  B . Then consider all the vertices in turn and if a given vertex x has degree greater than half of the vertices not yet considered, then place it in pile A and otherwise in pile B ; if x was placed in pile A (in pile B ), remove from the graph all vertices to which x is not (is) connected. Perform these operations until all vertices have been considered or removed. In each step we remove no more than half of the vertices, so we take at least log 2 n steps. In each step a vertex is added to one of the piles, so one of them has size at least 1 / 3 log 2 n vertices. Pile  A contains vertices forming a clique, and pile B contains vertices forming an anticlique.

0.15 假设P t = 0,求解Y公式,得到公式:Y = PM t ( − 1)//( M t − 1)。对于P = $100,000、I = 0.05 且t = 360,我们得到M = 1 + (0.05)/12。然后,您可以使用计算器确定每月付款为Y » 536.82 美元。

0.15 We set P t = 0 and solve for Y to get the formula: Y = PM t ( − 1)//( M t − 1). For P = $100,000, I = 0.05, and t = 360, we get M = 1 + (0.05)/12. We can then use a calculator to determine that Y's monthly payment is $536.82.

1

正则语言

1

Regular languages

计算理论始于这样一个问题:什么是计算机?这可能是一个愚蠢的问题,因为每个人都知道我写的是计算机。但这些真实的计算机很复杂——太复杂了,我们无法直接在它们之上构建可管理的数学理论。相反,我们将使用称为计算模型的理想化计算机。与科学中的任何模型一样,计算模型在某些方面可能是准确的,但在其他方面可能不准确。因此,我们将根据我们想要关注的特征使用许多不同的计算模型。我们将从最简单的模型开始,称为有限状态机( FSM )或有限自动机

The Theory of Computation begins with the question: What is a computer? This is probably a silly question, since everyone knows that what I’m writing about is a computer. But real computers are complex—too complex for us to be able to construct a manageable mathematical theory directly on them. Instead, we’ll use an idealized computer called a computational model . As with any model in science, a computational model can be accurate in some respects but probably not in others. So we’ll use a variety of different computational models, depending on the features we want to focus on. We’ll start with the simplest model, called a finite-state machine ( FSM ) or finite state machine .

1.1

有限自动机

1.1

Finite automata

有限状态机对于内存极其有限的计算机来说是很好的模型。这么小的内存电脑能做什么呢?很多有用的东西!事实上,我们一直在与此类计算机打交道,因为它们构成了各种机电设备的核心。

Finite state machines are good models for computers with extremely limited amounts of memory. What can a computer with such a small amount of memory do? Lots of useful things! In fact, we deal with such computers all the time, as they are the core of various electromechanical devices.

这种设备的示例可以是自动门控制器。通常在超市入口和出口发现,当控制器检测到有人接近时,自动门就会打开。自动前门有一个垫子,可以检测即将进门的人的存在。第二个垫子位于门口的后部,以便控制器可以将门保持打开足够长的时间以供人员通过,并防止门在打开时撞到后面的人。此配置如下图所示。

An example of such a device is an automatic door controller. Commonly found in supermarket entrances and exits, automatic doors open when the controller detects a person approaching. The automatic door at the front has a pad that detects the presence of a person who is about to pass through the door. A second pad is located at the rear of the passage, so that the controller can hold the door open long enough for the person to pass through, and also to prevent the door from hitting someone standing behind it as it opens. This configuration is shown in the figure below.

1.1

自动门俯视图

Figure 1.1

Top view of automatic doors

控制器处于两种状态之一:“OPEN”(打开)或“CLOSED”(关闭),代表适当的门状态。如下图所示,我们有四种可能的输入条件:“FRONT”(表示该人站在过道的前垫上)、“REAR”(表示该人站在过道的后垫上) )、“BOTH”(意味着人们站在两个垫子上)和“NEITHER”(意味着没有人站在任一垫子上)。

The controller is in one of two states: "OPEN" or "CLOSED", representing the corresponding state of the door. As you can see in the following figures, there are four possible entry conditions: "FRONT" (meaning that the person is standing on the front pad of the passage), "REAR" (meaning that the person is standing on the pad at the back of the passage), "BOTH" (meaning that people are standing on both pads), and "NEITHER" (meaning that no one is standing on either pad).

1.2

自动门控制器状态图

Figure 1.2

State diagram for automatic door controller

输入信号

input signal

两者都不

NEITHER

正面

FRONT

后部

REAR

两个都

BOTH

状态

state

关闭

CLOSED

关闭

CLOSED

打开

OPEN

关闭

CLOSED

关闭

CLOSED

打开

OPEN

关闭

CLOSED

打开

OPEN

打开

OPEN

打开

OPEN

1.3

自动门控制器状态转换表

Figure 1.3

State Transition Table for Automatic Door Controller

控制器根据其接收到的输入信号从一个状态移动到另一个状态。如果它处于 CLOSED 状态并且接收到 NEITHER 或 REAR 信号,则它保持在 CLOSED 状态。此外,如果它收到两个输入,它会保持关闭状态,因为打开门意味着有撞到站在后垫上的人的风险。然而,当 FRONT 信号到达时,它进入 OPEN 状态。在OPEN状态下,如果接收到FRONT、REAR或BOTH输入信号,则保持OPEN状态。如果没有输入信号到达,控制器将返回到“关闭”状态。

The controller changes from one state to another depending on the input signal it receives. If it is in the CLOSED state and receives a NEITHER or REAR signal, it remains in the CLOSED state. Additionally, if it receives a BOTH input signal, it remains in the CLOSED state because opening the door would mean the risk of hitting someone standing on the rear pad. However, when the FRONT signal arrives, it changes to the OPEN state. In the OPEN state, if it receives a FRONT, REAR or BOTH input signal, it remains in the OPEN state. If a NEITHER input signal arrives, the controller returns to the CLOSED state.

例如,控制器可以在关闭状态下启动并接收一系列前、后、均不、前、两者、均不、后和均不输入信号。结果,会经历CLOSED(初始)、OPEN、OPEN、CLOSED、OPEN、OPEN、CLOSED、CLOSED、CLOSED等一系列状态。

For example, a controller may start in the CLOSED state and receive a series of input signals FRONT, REAR, NEITHER, FRONT, BOTH, NEITHER, REAR, and NEITHER. As a result, it will cycle through a series of states CLOSED (initial), OPEN, OPEN, CLOSED, OPEN, OPEN, CLOSED, CLOSED, and CLOSED.

将自动门控制器视为有限状态机很有用,因为它可以让您理解标准表示形式,如图 1.2 和 1.3 中的表示形式。该控制器是一台只有一位内存的计算机,能够记录控制器所处的两种状态中的哪一种。其他常见设备的驱动程序内存稍大。在电梯控制器中,状态可以代表电梯所在的楼层,并且输入数据可以是从按钮接收的信号。该计算机可能需要许多位来存储该信息。各种家用电器(例如洗碗机或电子恒温器)的控制器以及数字时钟和计算器的部件是内存有限的计算机的其他示例。在设计此类设备时,必须考虑有限自动机的方法和术语。

Considering an automatic door controller as a finite-state machine is useful because it allows us to understand standard representations such as those in Figures 1.2 and 1.3. This controller is a computer that has only a single bit of memory that can record which of two states the controller is in. Other common devices have controllers with slightly larger memories. In an elevator controller, the state might represent the floor on which the elevator is located, and the input might be signals received from buttons. This computer might need many bits to store this information. Controllers for various home appliances, such as dishwashers or electronic thermostats, and parts of digital clocks and calculators, are additional examples of computers with finite memory. Finite-state machine methodology and terminology must be kept in mind when designing such devices.

有限状态机及其概率对应物马尔可夫链在尝试识别数据模式时是有用的工具。此类设备用于语音处理和光学字符识别。马尔可夫链甚至用于建模和预测金融市场的价格变动。

Finite state machines and their probabilistic counterpart, Markov chains , are useful tools when trying to recognize patterns in data. Such devices are used in speech processing and optical character recognition. Markov chains are even used to model and predict price movements in financial markets.

现在我们将从数学的角度来看有限自动机。我们将制定有限自动机的精确定义、描述和操作有限自动机的术语以及显示其优点和局限性的理论结果。除了更好地理解有限状态机是什么以及它们能做什么和不能做什么之外,这种理论发展还将使读者能够在简单的环境中练习并更有信心地使用数学定义、定理和证明。

We will now look at finite state machines from a mathematical perspective. We will develop a precise definition of a finite state machine, a terminology for describing and manipulating finite state machines, and theoretical results that illustrate their power and limitations. In addition to providing a better understanding of what finite state machines are and what they can and cannot do, such theoretical developments will allow the reader to practice and become more confident in using mathematical definitions, theorems, and proofs in a simple environment.

首先,为了描述有限自动机的数学理论,我们将进行抽象描述,而不涉及任何具体应用。下图显示了一个名为M 1的有限自动机。

At first, to describe the mathematical theory of finite automata, we will do it abstractly, without referring to any specific application. The figure below shows a finite automaton called M 1 .

1.4具有三种状态的

有限机M 1

Figure 1.4

Finite state machine M 1 with three states

图1.4称为M 1状态图 。它具有三个状态,描述为q 1q 2q 3。初始状态q 1由从外部进入的箭头标记。接受q 2 的状态是用双圆圈标记的状态。从一种状态引导到另一种状态的箭头称为转换

Figure 1.4 is called the state diagram of M 1 . It has three states labeled q 1 , q 2 , and q 3 . The initial state q 1 is marked with an arrow entering it from the outside. The accepting state q 2 is the one marked with a double circle. The arrows leading from one state to another are called transitions .

当该自动机接收到输入词(例如1101 )时,它会对其进行处理并传递结果,该结果是Accept拒绝。目前,为了简单起见,我们将只处理这些是/否结果。处理开始于机器M 1的初始状态。自动机从左到右一一读取输入单词中的符号。读取每个符号后,M 1沿着转换从一种状态移动到另一种状态,并以该符号作为其标签。读取最后一个符号后,M 1创建输出。如果M 1当前处于接受状态,则该输出为接受,如果不是,则拒绝。

When this automaton receives an input word, for example 1101 , it processes it and produces an output, which is either accept or reject . For now, for simplicity, we will only deal with such yes/no outputs. Processing begins in the initial state of the automaton M 1 . The automaton reads the symbols from the input word one by one, from left to right. After reading each symbol, M 1 moves from one state to another along a transition with the given symbol as its label. After reading the last symbol, M 1 produces an output. This output is accept if M 1 is currently in an accepting state, or reject if it is not.

例如,当我们将输入字1101传递给图1.4中的M1机器时,处理过程如下:

For example, when we pass input word 1101 to machine M1 in Figure 1.4, processing is as follows:

  1. 从状态q 1开始。
  2. Start in state q 1 .
  3. 读取1并从状态q 1转到q 2
  4. Read 1 and move from state q 1 to q 2 .
  5. 读取1并从状态q 2移动到q 2
  6. Read 1 and move from state q 2 to q 2 .
  7. 读取0并从状态q 2转到q 3
  8. Read 0 and move from state q 2 to q 3 .
  9. 读取1并从状态q 3移动到q 2
  10. Read 1 and move from state q 3 to q 2 .
  11. 接受,因为输入处理完成后M 1处于接受状态q 2 。
  12. Acceptance , since M 1 is in the accepting state q 2 after completing input processing.

对该机器进行各种输入单词的实验表明它接受单词101110101010101。事实上,M 1接受任何以1结尾的单词,因为每当它读取符号1时,它就会进入接受q 2的状态。此外,它还接受单词10001001100000101000000,以及最后一个1之后以偶数个零结尾的任何其他单词。拒绝其他单词,例如010101000。我们能否描述一种由M 1接受的所有单词组成的语言?我们稍后会这样做。

Experimenting with this machine for a variety of input words reveals that it accepts the words 1 , 01 , 11 , and 0101010101 . In fact, M 1 accepts any word ending in 1 , since it enters the state accepting q 2 whenever it reads the symbol 1 . In addition, it accepts the words 100 , 0100 , 110000 , and 0101000000 , as well as any other words ending with an even number of zeros following the final 1 . It rejects other words, such as 0 , 10 , 101000 . Could we describe the language consisting of all the words that M 1 accepts ? We will do that in a moment.

有限自动机的形式定义

Formal definition of a finite state machine

在上一节中,我们使用状态图来表示有限状态机。现在我们将正式定义一个有限自动机。虽然状态图更容易直观地理解,但我们也需要正式定义有两个原因。

In the previous section, we used state diagrams to represent finite state machines. Now we define a finite state machine formally. Although state diagrams are easier to understand intuitively, there are two reasons why we also need a formal definition.

首先,形式定义是精确的。它解决了有限状态机中允许的任何不确定性。如果我们不确定有限状态机是否允许有 0 个接受状态,或者对于每个可能的输入符号是否必须从每个状态中恰好有一次转换,我们可以查看正式定义并检查答案是否为“是”两种情况。其次,形式化定义引入了符号。好的符号可以帮助您清晰地反映和表达您的想法。

First, the formal definition is precise. It resolves any uncertainty about what is allowed in a finite state machine. If we are unsure whether it is allowed for a finite state machine to have 0 accepting states, or whether it must have exactly one transition out of each state for each possible input symbol, we can look at the formal definition and see that the answer is yes in both cases. Second, the formal definition introduces notation. Good notation helps us to reason and express our thoughts clearly.

正式定义的语言有些复杂,与法律文件的语言有些相似。两者都必须准确,每个细节都必须写得没有错误。

The language of a formal definition is somewhat convoluted, bearing some resemblance to the language of legal documents. Both must be precise and every detail must be written flawlessly.

有限状态机由几个部分组成。它包含一组状态和规则,用于根据输入符号从一个状态转换到另一个状态。它有一个输入字母表,包括允许的输入符号,以及一个初始状态和一组接受状态。正式定义表明,有限自动机是这五个对象的列表:一组状态、输入字母表、转换规则、初始状态和接受状态。在数学语言中,五个元素的列表通常称为有序五元组(5 元组)。因此,我们将有限自动机定义为由这五个部分组成的元组。

A finite state machine consists of several parts. It contains a set of states and rules for transitioning from one state to another depending on an input symbol. It has an input alphabet, which includes the allowed input symbols, as well as an initial state and a set of accepting states. The formal definition says that a finite state machine is a list of these five objects: the set of states, the input alphabet, the transition rules, the initial state, and the accepting states. In mathematical language, a list of five elements is often called an ordered five (5-tuple). So we define a finite state machine as a tuple consisting of these five parts.

为了描述状态之间转换的规则,我们将使用转换函数,通常用符号δ表示。如果有限状态机包含从状态x到状态y的转换(箭头) ,并用输入符号1标记,这意味着如果机器在读取1时处于状态x,则会转换到状态y。我们可以使用传递函数表示相同的动作,即δ ( x , 1) = y。这种类型的符号是一种数学捷径。将所有这些放在一起,我们得到了有限状态机的正式定义。

To describe the rules for transitioning between states, we will use a transition function , usually denoted by the symbol δ . If a finite state machine contains a transition (arrow) from state x to state y , labeled with the input symbol 1 , this means that if the machine is in state x when 1 is read , it goes to state y . We can denote the same action using a transition function, stating that δ ( x , 1) = y . This type of notation is a kind of mathematical shortcut. Putting all this together, we have the formal definition of a finite state machine.

定义 1.5

Definition 1.5

有限自动机是一个有序的五 ( Q , Σ , δ , q 0 , F ),其中

A finite automaton is an ordered five ( Q , Σ , δ , q 0 , F ), where

  1. Q是一个称为states 的有限集,
  2. Q is a finite set called states ,
  3. Σ是一个称为字母表的有限集,
  4. Σ is a finite set called an alphabet ,
  5. δ : Q × ΣQ传递函数1
  6. δ : Q × ΣQ is the transition function 1 ,
  7. q 0 Q初始状态
  8. q 0 Q is the initial state ,
  9. F Q是接受2 的状态集
  10. F Q is the set of states accepting 2 .

形式定义精确地定义了有限自动机的含义。例如,如果我们回到前面是否允许 0 个接受状态的问题,我们可以看到将F设置为空集Ø给出 0 个接受状态,这是允许的。此外,转换函数δ准确地确定当前状态和输入符号的每种可能组合的下一个状态。这证实了第二个问题的答案,即对于每个可能的输入符号,每个状态必须恰好有一个转换。

The formal definition precisely specifies what we mean by a finite automaton. For example, if we return to the earlier question of whether 0 accepting states are allowed, we can see that setting F to the empty set Ø gives 0 accepting states, which is allowed. Moreover, the transition function δ determines exactly one next state for each possible combination of the current state and the input symbol. This implies a positive answer to the second question, namely that there must be exactly one transition from each state for each possible input symbol.

我们可以通过指定定义 1.5 中列举的五个部分中的每一个来使用形式符号来描述特定的有限自动机。让我们回到前面讨论的有限自动机M 1,为了方便起见,再次在这里绘制。

We can use formal notation to describe concrete finite automata by specifying each of the five parts enumerated in Definition 1.5. Let us return to the finite automaton M 1 discussed earlier , redrawn here for convenience.

1.6

有限机M 1

Figure 1.6

Finite state machine M 1

我们可以通过写 M 1 = ( Q , Σ , δ , q 1 , F )来正式描述M 1 ,其中

We can formally describe M 1 by writing M1 = ( Q , Σ , δ , q 1 , F ), where

  1. Q = { q 1 , q 2 , q 3 },
  2. Q = { q1 , q2 , q3 } ,
  3. Σ = { 0 , 1 },
  4. Σ = { 0 , 1 },
  5. δ如表所示

    0

    1

    q 1

    q 1

    q 2

    q 2

    q 3

    q 2

    q 3

    q 2

    q 2

  6. δ is described by the table

    0

    1

    q1

    q1

    q2

    q2

    q3

    q2

    q3

    q2

    q2

  7. q 1是初始状态,
  8. q 1 is the initial state,
  9. F = { q 2 }。
  10. F = { q 2 }.

如果A是机器M接受的所有单词的集合,那么我们说A机器M的语言,并将其写为L ( M )= A。然后我们说M 认识AM 接受A。因为当我们指代接受单词的机器时,术语“接受”与指语言接受时具有不同的含义,因此在指代语言时,我们更喜欢使用术语“识别”,以避免混淆。

If A is the set of all words accepted by a machine M , then we say that A is the language of M , and we write this as L ( M ) = A . We then say that M recognizes A or that M accepts A . Since the term accepts has different meanings when we refer to the acceptance of words by a machine and different meanings when we refer to the acceptance of languages, we prefer the term recognizes when referring to languages ​​to avoid confusion.

机器可以接受许多单词,但它只能识别一种语言。如果机器不接受任何单词,它仍然会识别一种语言 - 特别是空语言Ø

The machine can accept many words, but it will always recognize only one language. If the machine does not accept any words, it still recognizes one language – specifically, the empty language Ø .

在我们的例子中,让

In our example, let

A = { w : w至少包含一个 1 和最后一个1之后的偶数个 0 }。

A = { w : w contains at least one 1 and an even number of zeros following the last 1 }.

那么L ( M 1 ) = A,或者等效地M 1识别A

Then L ( M 1 ) = A , or equivalently M 1 recognizes A .

有限自动机的例子

Examples of Finite State Machines

1.7

Example 1.7

有限机M 2的状态图如下所示。

The state diagram of the finite state machine M 2 is shown below .

1.8

二状态有限机M 2的状态图

Figure 1.8

State diagram for a two-state finite machine M 2

在形式化描述中,M 2为({ q 1 , q 2 },{ 0 , 1 }, δ , q 1 ,{ q 2 })。传递函数δ

In the formal description M 2 is ({ q 1 , q 2 }, { 0 , 1 }, δ , q 1 , { q 2 }). The transition function δ is

0

0

1

1

q 1

q1

q 1

q1

q 2

q2

q 2

q2

q 1

q1

q 2

q2

重要的是要记住,状态图和M 2的正式定义包含相同的信息,只是形式不同。如果需要,我们随时可以从一种切换到另一种。

It is important to remember that the state diagram and the formal definition of M 2 contain the same information, only in a different form. We can always switch from one to the other if necessary.

了解给定机器如何工作的一个好方法是使用一些示例输入进行尝试。当我们进行这样的“实验”来了解机器如何工作时,它的操作方法往往会变得显而易见。对于示例字1101,M 2机器从初始状态q 1开始,在读取第一个1后首先移动到状态q 2,然后依次移动到状态q 2q 1,最后在读取10后移动到q 2,和1。该词被接受,因为q 2是接受状态。然而,字110使M 2处于状态q 1,因此它被拒绝。尝试了其他几个例子后,我们可以看到M 2接受所有以1结尾的单词。因此L ( M 2 ) = { w : w以1结尾}。

A good way to understand how a machine works is to try it out on a few sample inputs. When we do these “experiments” to get a feel for how a machine works, its method of operation often becomes obvious. For example, for word 1101, machine M 2 starts in state q 1 and moves first to state q 2 after reading the first 1 , then to states q 2 , q 1 , and finally to q 2 after reading 1 , 0 , and 1 . The word is accepted because q 2 is an accepting state. Word 110 , on the other hand , leaves M 2 in state q 1 and is therefore rejected. After trying a few more examples, we can see that M 2 accepts all words ending in 1 . Thus, L ( M 2 ) = { w : w ends in 1 }.

1.9

Example 1.9

让我们考虑有限机器M 3

Consider a finite automaton M 3 .

1.10

二状态有限机M 3的状态图

Figure 1.10

State diagram for a two-state finite state machine M 3

除了接受状态的位置之外,M 3机器与M 2类似。像往常一样,机器接受所有单词,当它完成阅读时,它会处于接受状态。注意,由于初始状态也是接受状态,所以M 3接受空字ε。机器一开始读取空白字,就已经读到最后了;因此,如果初始状态是接受状态,则ε被接受。除了空白之外,本机接受任何以0结尾的单词。因此

Machine M 3 is similar to M 2 except for the location of the accepting state. As usual, the machine accepts all words that leave it in the accepting state after it finishes reading them. Note that since the start state is also an accepting state, M 3 accepts an empty word ε . As soon as the machine starts reading an empty word, it is already at the end; therefore, if the start state is an accepting state, ε is accepted. Apart from an empty word, this machine accepts any word ending in 0 . Thus

L ( M 3 ) = { w : w是空词ε或以0结尾}。

L ( M 3 ) = { w : w is the empty word ε or ends with 0 }.

1.11

Example 1.11

下图显示了具有五种状态的M 4机器。

The figure below shows a five-state machine M 4 .

1.12

有限机M 4

Figure 1.12

Finite state machine M 4

M 4机器包含两个接受状态q 1r 1并在字母表Σ = { a , b } 上进行操作。多项实验表明,它接受单词abaabbbab,但不接受单词abbabbba。机器从状态s开始,从输入读取第一个符号后,它向左移动到状态q或向右移动到状态r。在这两种情况下,它永远无法返回到初始状态(与前面的示例不同),因为无法从任何其他状态返回到s。如果第一个输入符号是a,则它向左移动并接受以a结尾的单词。同样,如果第一个符号是b,机器向右移动并接受以b结尾的单词。因此M 4接受所有以a开头和结尾或以b开头和结尾的单词。换句话说,M 4接受以相同符号开头和结尾的单词。

A machine M 4 contains two states accepting q 1 and r 1 and operates over the alphabet Σ = { a , b }. Several experiments show that it accepts the words a , b , aa , bb , and bab , but not the words ab , ba , or bbba . The machine starts in state s , and after reading the first symbol from the input, it either moves left to states q , or right to states r . In either case, it can never return to the initial state (unlike the previous examples), since there is no way to get from any other state back to s . If the first input symbol is a , it moves left and accepts the word if it ends in a . Similarly, if the first symbol is b , the machine moves right and accepts the word if it ends in b . Thus, M 4 accepts all words that start and end with a or start and end with b . In other words, M 4 accepts those words that begin and end with the same symbol.

1.13

Example 1.13

图 1.14 显示了在四符号字母表上运行的三状态机M 5 , Σ = { < RESET > , 0 , 1 , 2 }。我们将〈RESET〉视为单个符号

Figure 1.14 shows a three-state machine M 5 operating over a four-symbol alphabet, Σ = { RESET , 0 , 1 , 2 }. We treat RESET as a single symbol.

1.14

有限机M 5

Figure 1.14

Finite state machine M 5

M 5机器计算读取的数字符号模3的运行总和。每次遇到符号 <RESET> 时它都会将计数器重置为 0。如果总和等于 0 模 3,或者在其他情况下,它接受输入单词,当总和是多个数字 3 时。

Machine M 5 counts the running sum of the numeric symbols read modulo 3. Each time it encounters the symbol RESET , it resets the counter to 0. It accepts input if the sum is equal to 0 modulo 3, or in other words, if the sum is a multiple of 3.

在某些情况下,不可能用状态图来表示有限状态机。当图表太大而无法绘制时,或者如果(如下一个示例中)描述依赖于某些未指定的参数时,可能会发生这种情况。在这种情况下,我们必须依靠正式定义来指定机器。

In some cases it is not possible to represent a finite state machine by a state diagram. This may happen when the diagram is too large to draw, or if (as in the next example) the description depends on some unspecified parameter. In such cases we must rely on a formal definition to specify the machine.

1.15

Example 1.15

考虑示例 1.13 的概括。我们仍将使用相同的四符号Σ字母表。令,对于每个i ≥ 1,语言A i包含所有数字总和为i倍数的单词,并且在求和过程中,只要出现符号<RESET> 我们就重置计数器。对于每个A i ,我们将呈现一个有限自动机B i来识别A i。我们可以将机器B i正式描述如下:Bi = ( Q i , Σ , δ i , q 0 , { q 0 }),其中Q i是i 个状态的集合{ q 0 , q 1 , q 2 , …, q i −1 },我们将设计传递函数δ i ,以便对于每个j,如果B i处于状态q j ,则每个q j的运行和为j模 Let 。

Consider a generalization of Example 1.13. We will still use the same four-symbol alphabet Σ . For each i ≥ 1, let the language A i contain all words whose sum is a multiple of i , where we reset the counter during the summation whenever the symbol RESET appears . For each A i , we represent a finite automaton B i that recognizes A i . The machine B i can be described formally as follows: B i = ( Q i , Σ , δ i , q 0 , { q 0 }), where Q i is a set of i states { q 0 , q 1 , q 2 , …, q i −1 }, and the transition function δ i is designed so that for each j , if B i is in state q j , the running sum is j modulo i. Let for each q j

δ i ( q j , 0 ) = q j ,

δ i ( q j , 0 ) = q j ,

δ i ( q j , 1 ) = q k,其中k = j + 1 模i

δ i ( q j , 1 ) = q k , where k = j + 1 modulo i ,

δ i ( q j , 2 ) = q k,其中k = j + 2 模i

δ i ( q j , 2 ) = q k , where k = j + 2 modulo i ,

δ i ( q j , <重置> ) = q 0

δ i ( q j , RESET ) = q 0 .

计算的正式定义

Formal definition of computation

到目前为止,我们已经非正式地使用状态图描述了有限状态机,正式地描述为有序五状态机。非正式描述最初更容易理解,但正式定义有助于通过解决非正式描述中可能出现的任何歧义来提供见解的精确性。现在我们将对有限状态机执行的计算(处理)执行相同的操作。我们已经对它如何执行计算有了一个非正式的想法,现在我们将以数学形式将其形式化。

So far, we have described finite state machines informally using state diagrams and with a formal definition as an ordered five. The informal description is easier to initially understand, but the formal definition is useful in ensuring the precision of the observations by resolving any ambiguities that may arise in the informal description. Now we do the same for the computations (processing) performed by the finite state machine. We now have an informal understanding of how it performs its computations, and now we formalize this mathematically.

M = ( Q , Σ , δ , q 0 , F ) 为有限自动机,并令w = w 1 w 2 …w n为单词,其中每个w i是字母表Σ中的符号。如果存在属于Q的状态序列r 0 , r 1 , …, r n,并且满足三个条件,则机器M 接受 w:

Let M = ( Q , Σ , δ , q 0 , F ) be a finite automaton and let w = w 1 w 2 …w n be a word, where each w i is a symbol from the alphabet Σ . The machine M accepts w if there is a sequence of states r 0 , r 1 , …, r n belonging to Q , satisfying three conditions:

  1. r 0 = q 0
  2. r0 = q0 ;
  3. δ ( r i , w i +1 ) = r i +1 对于i = 0, …, n − 1;
  4. δ ( r i , w i +1 ) = r i +1 for i = 0, …, n − 1;
  5. r n F
  6. r n F .

条件 1 表明机器在其初始状态下启动。条件 2 表明机器根据转换函数从一个状态移动到另一个状态。条件 3 表示如果机器以接受状态退出,则机器接受输入。如果A = { w : M接受w },我们就说M 识别语言 A。

Condition 1 states that the machine starts in the initial state. Condition 2 states that the machine moves from state to state according to a transition function. Condition 3 states that the machine accepts input if it ends in an accepting state. We say that M recognizes a language A if A = { w : M accepts w }.

定义 1.16

Definition 1.16

如果一种语言被某个有限自动机识别,则该语言被称为正则语言。

A language is called a regular language if it is recognized by a finite automaton.

1.17

Example 1.17

让我们假设示例 1.13 中的M 5机器。让w成为一个词

Let us assume the machine M 5 from Example 1.13. Let w be a word

10 重置22 重置012

10 RESET 22 RESET 012 .

那么M 5按照计算的形式定义接受w ,因为它在处理w 的过程中进入的状态序列是

Then M 5 accepts w according to the formal definition of computation, since the sequence of states it enters during the processing of w is

q 0 , q 1 , q 1 , q 0 , q 2 , q 1 , q 0 , q 0 , q 1 , q 0 ,

q 0 , q 1 , q 1 , q 0 , q 2 , q 1 , q 0 , q 0 , q 1 , q 0 ,

满足所有三个条件。M 5机器的语言是

that meets all three conditions. The language of the M 5 machine is

L ( M 5 ) = { w :属于w符号之和为 0 模 3,除了符号<RESET>将计数器重置为 0}。

L ( M 5 ) = { w : the sum of the symbols belonging to w is 0 modulo 3, except that the symbol RESET resets the counter to 0}.

由于M 5可以识别这种语言,因此它是一种正则语言。

As M 5 recognizes this language, it is a regular language.

有限自动机的设计

Designing Finite State Machines

无论是机器还是图形,设计都是一个创造性的过程。因此,它不能简化为简单的配方或配方。尽管如此,可以看出,在设计不同类型的机器时,特定的方法是有帮助的。这包括将我们自己置于我们正在尝试设计的机器的立场上,看看我们应该做什么来完成该机器的任务。假装成一台机器是一种心理技巧,可以帮助我们全身心投入到设计过程中。

Whether it is a machine or a graphic, design is a creative process. As such, it cannot be reduced to a simple recipe or pattern. Nevertheless, it can be seen that a particular approach is helpful in designing different types of machines. This consists in putting ourselves in the place of the machine we are trying to design and seeing how we should proceed in order to accomplish the task of that machine. Pretending to be a machine is a psychological trick that helps to involve our whole mind in the design process.

让我们尝试使用刚刚描述的“阅读器作为自动机”方法来设计一个有限状态机。假设我们有一种特定的语言,并且我们想要设计一个能够识别它的有限自动机。当扮演自动机的角色时,我们收到一个输入单词,我们必须确定它是否是我们的自动机应该识别的语言元素。我们将一次读一个单词符号。在每个符号之后,我们必须判断我们目前看到的单词是否属于该语言。这样做的原因是,就像机器一样,我们不知道单词何时结束,因此我们必须始终准备好答案。

Let us try to design a finite automaton using the "reader as automaton" method just described. Suppose we have a language and we want to design a finite automaton that recognizes it. Playing the role of the automaton, we are given an input word and we need to determine whether it is an element of the language that our automaton is supposed to recognize. We will read the symbols of the word one at a time. After each symbol we need to decide whether the word seen so far belongs to the language. The reason for this is that, like a machine, we do not know when the end of the word will be, so we must always have the answer ready.

首先,为了做出这样的决定,我们需要确定在阅读时我们需要记住我们正在学习的单词的哪些内容。为什么我们不能记住我们所看到的一切?我们必须记住,我们希望表现得像有限状态机,而这种类型的机器只有有限数量的状态,这意味着有限的内存。让我们想象一下,输入数据非常长——比如说从这里到月球——所以我们无法完整地记住它。我们的记忆是有限的——例如一张纸——容量也是有限的。幸运的是,要识别许多语言,我们不必记住整个输入单词。我们只需要记住关键信息即可。到底哪些信息是关键取决于所考虑的特定语言。

To make such decisions, we first need to figure out what we need to remember about the word we are learning as we read it. Why couldn’t we just remember everything we saw? It’s important to remember that we want to behave like a finite-state machine, and such a machine has only a finite number of states, which means a finite memory. Imagine that the input data is extremely long—say, from here to the moon—so we won’t be able to remember all of it. We have a finite memory—a single piece of paper, for example—with a finite capacity. Fortunately, for recognizing many languages, we don’t need to remember the entire input word. We only need to remember the key information. The exact definition of what information is key depends on the particular language being considered.

例如,假设字母表是集合 { 0 , 1 } 并且该语言由包含奇数个 1 的所有单词组成。我们想要构建一个能够识别这种语言的有限机器E 1 。假装我们是一个自动机,我们开始逐个符号地读取由 0 和 1 组成的输入字符串。我们是否需要记住到目前为止所见过的整个单词来确定 1 的数量是否为奇数?当然不是。您所需要做的就是记住到目前为止看到的 1 的数量是偶数还是奇数,并在读取新符号时跟踪这些信息。当我们读到1时,我们改变了答案;然而,当我们读取0时,我们将其保持不变。

For example, suppose the alphabet is the set { 0 , 1 } and that the language consists of all words that contain an odd number of ones. We want to construct a finite automaton E 1 that recognizes this language. Pretending to be the automaton, we begin reading the input sequence of zeros and ones, symbol by symbol. Do we need to memorize the entire word we've seen so far to determine whether the number of ones is odd? Of course not. All we need to do is memorize whether the number of ones we've seen so far is odd or even, and keep track of that information as we read new symbols. When we read a 1 , we change our answer; however, when we read a 0 , we leave it unchanged.

但这如何帮助我们设计E 1机器呢?一旦我们确定了在阅读过程中需要记住输入单词的哪些信息,我们就可以将该信息呈现为有限的可能性列表。在这种情况下,这些可能性是

But how could this help us design the E 1 machine ? Once we have determined what information about the input word needs to be remembered while reading it, we can represent this information as a finite list of possibilities. In this case, the possibilities are

  1. 即使到目前为止,
  2. so far even,
  3. 到目前为止很奇怪。
  4. so far odd.

然后我们为每种可能性分配一个状态。图 1.18 显示了E 1的状态。

We then assign a state to each of these possibilities. Figure 1.18 shows the states E 1 .

1.18

两种状态q parq npar

Figure 1.18

Two states q par and q npar

然后我们分配转换,检查我们需要如何根据读取的符号从一种可能性转移到另一种可能性。因此,如果状态q par r表示偶数可能性,而q npar表示奇数可能性,则我们创建导致状态更改为1并保持在原地为0 的转换,如下所示。

Next , we assign transitions, seeing how we need to go from one possibility to another depending on the symbol read. So if the state q par represents an even possibility, and q npar an odd possibility, then we create transitions that cause a 1 to change state and a 0 to stay put , as below.

1.19

显示能力如何变化的转换

Figure 1.19

Transitions showing how the possibilities change

然后,我们将初始状态设置为与到目前为止读取0 个符号(空字 ε)相关的可能性相对应的状态。在这种情况下,初始状态对应于状态q,因为0是偶数。最后,我们将接受状态设置为与我们想要接受输入单词的可能性相对应的状态。我们将q npar设置为接受状态,因为只要我们看到奇数个单词,我们就想接受一个单词。这些添加如下图所示。

Next, we set the initial state to what should be the state corresponding to the possibility associated with reading 0 symbols  so far (the empty word ε ). In this case, the initial state corresponds to the state q par , since 0 is an even number. Finally, we set the accepting states to those corresponding to the possibility in which we want to accept the input word. We set q npar as the accepting state, since we want to accept the word if we see an odd number of ones. These additions are shown in the figure below.

1.20

添加初始状态和接受状态

Figure 1.20

Adding Initial and Accepting States

1.21

Example 1.21

在这个例子中,我们将展示如何设计一个有限机器E 2来识别由所有包含001作为子词的单词组成的正则语言。例如,单词0010100100111111110011111属于该语言,而单词110000则不属于该语言。如果我们是E 2自动机,我们如何才能尝试识别这种语言?当我们阅读后续符号时,我们最初会跳过所有符号。如果我们遇到0,我们注意到这样一个事实:我们可能刚刚看到了我们正在寻找的模式的三个符号中的第一个,001。如果此时我们看到1,则说明零太少,因此我们返回跳过这些零。然而,如果我们现在看到0,我们应该记住我们刚刚看到了两个模式符号。现在我们需要继续扫描直到看到1。如果找到它,我们就会记住我们找到了该模式并继续读取输入直到结束。

In this example, we will show how to design a finite-state machine E 2 that recognizes a regular language consisting of all words that contain 001 as a subword. For example, the words 0010 , 1001 , 001 , and 11111110011111 belong to this language, while the words 11 and 0000 do not. How could we try to recognize this language if we were the machine E 2 ? As we read the symbols, we will initially skip all the ones. If we come across a 0 , we note the fact that we may have just seen the first of three symbols of the pattern 001 . If we see a 1 at this point , there were too few zeros, so we go back to skipping ones. However, if we now see a 0 , we should remember that we have just seen two symbols of the pattern. Now we need to continue scanning until we see a 1 . If we find it, we remember that we found a pattern and continue reading the input until the end.

所以我们有四种可能:

So we have four options:

  1. 我们还没有看到任何图案符号,
  2. We haven't seen any pattern symbols yet,
  3. 我们刚刚看到0 ,
  4. We just saw 0 ,
  5. 我们刚刚看到00 ,
  6. We just saw 00 ,
  7. 我们看到了整个001的图案。
  8. We saw the entire pattern 001 .

对于这些可能性,我们分配状态qq 0q 00q 001。然后,我们可以通过注意到在状态q中读取1后我们仍处于q状态来分配转换,但读取0会使我们转到q 0。在状态q 0 中,读取1返回到q,但读取0将我们移动到q 00。在状态q 00 中,读取1后我们转到q 001,但读取0会使我们停留在q 00。最后,在状态q 001 中,读取任何符号(01)都会导致状态保持在q 001中。初始状态为q,唯一接受状态为q 001,如图 1.22 所示。

We assign states q , q 0 , q 00 , and q 001 to these possibilities . We can then assign transitions by noting that in state q , reading 1 leaves us in q , but reading 0 leaves us in q 0 . In state q 0 , reading 1 leaves us in q , but reading 0 leaves us in q 00 . In state q 00 , reading 1 leaves us in q 001 , but reading 0 leaves us in q 000 . Finally, in state q 001 , reading any symbol ( 0 or 1 ) leaves us in q 001 . The initial state is q , and the only accepting state is q 001 , as shown in Figure 1.22.

1.22

接受包含001的单词

Figure 1.22

Accepting words containing 001

正则操作

Regular operations

在前两节中,我们介绍并定义了有限自动机和正则语言。我们现在将检查它们的属性。这样做将有助于构建一套方便的技术来设计识别特定语言的机器。该集合还将包括证明某些其他语言非正则(即超出有限自动机的能力)的方法。

In the previous two sections, we introduced and defined finite automata and regular languages. We now turn to the study of their properties. This procedure will help us build a handy set of techniques for designing automata that recognize specific languages. This set will also include methods for proving that certain other languages ​​are not regular (that is, beyond the capabilities of finite automata).

在算术中,基本对象是数字,处理数字的工具是+、×等运算。在计算理论中,这些对象是语言,并且使用专门设计的工具来操作它们。我们将定义三种语言操作,称为正则操作,并使用它们来研究正则语言的属性。

In arithmetic, the basic objects are numbers, and the tools for processing them are operations such as + and ×. In the theory of computation, such objects are languages, and they are operated on using specially designed tools. We will define three operations on languages, called regular operations, and then use them to study the properties of regular languages.

定义 1.23

Definition 1.23

A和 B为语言。我们将定义联合、串联和星号(克林闭包的正则操作:

Let A and  B be languages. We define the regular operations union, concatenation, and star (Kleene closure ) :

  • 总和:A B = { x : x Ax B }。
  • Sum: A B = { x : x A or x B }.
  • 连接:A B = { xy : x Ay B }。
  • Concatenation: A B = { xy : x A and y B }.
  • 星号:A * = { x 1 x 2 … x k : k ≥ 0 并且每个x i A }。
  • Asterisk: A * = { x 1 x 2 … x k : k ≥ 0 and each x i A }.

求和运算是已知的。它涉及从语言A和 B中获取所有单词并创建一组。

The operation of sum is already known. It consists of taking all the words from both languages ​​A and  B and creating a single set from them.

串联操作有点困难。它涉及以各种可能的方式将语言A中的单词附加到语言B中的单词的开头,从而创建新语言的单词。

The operation of concatenation is a bit more difficult. It involves attaching words from language A to the beginning of words from B in all possible ways, creating words of a new language.

星号操作(Kleene包)与其他两种操作略有不同,因为它适用于一种语言,而不是两种不同的语言。因此,该操作是一个参数,而不是两个参数。它的工作原理是组合语言A中任意数量的单词来创建新语言的单词。由于“任何数字”都包含 0 作为其可能性之一,因此空词ε始终是语言A *的元素,无论A是什么。

The asterisk operation (Kleene 's closure ) is slightly different from the other two, because it applies to a single language, not two different ones. This operation is therefore a single-argument operation, not a binary one. It works by combining any number of words from language A to form a word of the new language. Since "any number" includes 0 as one possibility, the empty word ε is always an element of language A * no matter what A is .

1.24

Example 1.24

令字母表Σ为标准 26 个字母 { a , b , …, z }的集合。如果A = {,} 且B = {男孩,女孩},则

Let the alphabet Σ be the set of standard 26 letters { a , b , …, z }. If A = { good , bad } and B = { boy , girl }, then

A∪B = {男孩女孩} ,

A B = { good , bad , boy , girl },

A B = {好男孩,好女孩,坏男孩,坏女孩},

A B = { goodboy , goodgirl , badboy , badgirl },

A * = { ε ,,,好好,好坏,坏好,坏坏,好好好,好好坏,好坏好,好坏坏, …}。

A * = { ε , good , bad , goodgood , goodbad , badgood , badbad , goodgoodgood , goodgoodbad , goodbadgood , goodbadbad , …}.

N = {1, 2, 3, …} 为自然数集。当我们说集合N在乘法下是闭集时,我们的意思是对于任何属于 N 的xy 乘积x × y也属于N。相反,N在除法下不是封闭的,因为 1 和 2 属于N,但 1/2 不是。一般来说,如果将某个操作应用于该集合的元素会返回属于该集合的对象,则该对象集合相对于某个操作是封闭的。我们将证明正则语言集对于所有三个正则操作都是封闭的。在第 1.3 节中,我们将展示这些是处理正则语言和理解有限自动机的强大功能的有用工具。我们将从求和运算开始。

Let N = {1, 2, 3, …} be the set of natural numbers. When we say that the set N is closed under multiplication, we mean that for any x and y in N , the product x × y is also in N . By contrast, N is not closed under division, since 1 and 2 are in N , but 1/2 is not. More generally, a set of objects is closed under some operation if applying that operation to the elements of the set returns an object in the set. We will show that the set of regular languages ​​is closed under all three regular operations. In Section 1.3, we will show that these are useful tools for processing regular languages ​​and for understanding the power of finite-state automata. We start with the union operation.

定理1.25

Theorem 1.25

正则语言的类由于并集操作而被封闭。

The class of regular languages ​​is closed under the union operation.

换句话说,如果A 1A 2是正则语言,则A 1 A 2也是正则语言。

In other words, if A 1 and A 2 are regular languages, then A 1 A 2 is also a regular language.

证明的概念 我们有正则语言A 1A 2,我们想证明A 1 A 2也是正则语言。由于A 1A 2是正则的,所以我们知道存在某个有限自动机M 1识别A 1和某个有限自动机M 2识别A 2。为了证明A 1 A 2是正则语言,我们将展示一个识别A 1 A 2的有限自动机M。

Concept of Proof We have regular languages ​​A 1 and A 2 and we want to show that A 1 A 2 is also a regular language. Since A 1 and A 2 are regular, we know that there is some finite automaton M 1 that recognizes A 1 and some finite automaton M 2 that recognizes A 2 . To prove that A 1 A 2 is a regular language, we show a finite automaton M that recognizes A 1 A 2 .

这是通过构造证明的。我们将基于M 1M 2构造M。为了识别语言的总和,机器M必须接受与M 1M 2接受的完备相同的单词的输入。它通过模拟机器M 1M 2来工作,并在任何一个模拟接受时接受。

This is a proof by construction. We construct M from M 1 and M 2 . In order to recognize the union of languages, the automaton M must accept its input for exactly the same words that either M 1 or M 2 accepts . It operates by simulating both automatons M 1 and M 2 , and accepts whenever either simulation would accept.

如何让机器M模拟M 1M 2?也许它会首先针对给定输入模拟M 1,然后再模拟M 2。不过,这里我们必须要小心!一旦输入符号被读取并用于模拟M 1,我们就无法“倒带”并尝试模拟M 2。我们需要一种不同的方法。

How can we make an automaton M simulate M 1 and M 2 ? Perhaps it will first simulate M 1 for a given input, and then simulate M 2 . But we have to be careful here! Once the input symbols have been read and used to simulate M 1 , we cannot "rewind the tape" and try to simulate M 2 . We need a different approach.

让我们想象一下我们是一个自动机M。当输入符号一一到达时,我们同时模拟M 1M 2。这样,只需要一次传递输入数据。但是我们如何用有限的内存来跟踪两个模拟呢?我们只需要记住每个自动机在读取输入单词时所处的状态。因此,我们需要记住成对的状态。有多少种可能的状态对?如果M 1包含k 1 个状态并且M 2k 2 个状态,则状态对(一个来自M 1另一个来自M 2 )的数量是k 1 × k 2的乘积。该乘积将是机器M的状态数,每对一个。M中的转换从对到对,更新机器M 1M 2的当前状态。M的接受状态是M 1M 2处于接受状态的那些对。

Imagine that we are an automaton M . As the input symbols arrive one by one, we simulate both M 1 and M 2 simultaneously. In this way, only one pass through the input is necessary. But how can we keep track of the two simulations with limited memory? We only need to remember the state that each automaton would be in if it read the input word to that point. Thus, we need to remember the pairs of states. How many possible pairs of states are there? If M 1 has k 1 states and M 2 has k 2 states , then the number of pairs of states, one from M 1 and the other from M 2 , is the product k 1 × k 2 . This product will be the number of states of M , one for each pair. Transitions in M ​​go from pair to pair, updating the current state for both M 1 and M 2 . The accepting states of M are those pairs in which either M 1 or M 2 is in an accepting state.

证明 M 1识别A 1,其中M 1 = ( Q 1 , Σ , δ 1 , q 1 , F 1 ),并且M 2识别A 2,其中M 2 = ( Q 2 , Σ , δ 2 , q 2 F 2)。

Proof Let M 1 recognize A 1 , where M 1 = ( Q 1 , Σ , δ 1 , q 1 , F 1 ), and M 2 recognize A 2 , where M 2 = ( Q 2 , Σ , δ 2 , q 2 , F 2 ).

我们构造一个自动机M来识别A 1 A 2,其中M = ( Q , Σ , δ , q 0 , F )。

We construct an automaton M that recognizes A 1 A 2 , where M = ( Q , Σ , δ , q 0 , F ).

  1. Q = {( r 1 , r 2 ) : r 1 Q 1r 2 Q 2 }。

    该集合是集合Q 1Q 2的笛卡尔积,我们将其写为Q 1 × Q 2。它是所有状态对的集合,其中第一个状态来自Q 1,第二个状态来自Q 2

  2. Q = {( r 1 , r 2 ) : r 1 Q 1 and r 2 Q 2 }.

    This set is the Cartesian product of the sets Q 1 and Q 2 and is written as Q 1 × Q 2 . This is the set of all pairs of states, the first of which comes from Q 1 and the second from Q 2 .

  3. Σ ,字母表,与M 1M 2中的相同。在该定理和所有后续类似定理中,为简单起见,我们假设M 1M 2具有相同的输入字母表Σ。如果它们都使用不同的字母Σ 1Σ 2,则该陈述仍然成立。然后我们只需假设Σ = Σ 1 Σ 2来修改证明。
  4. Σ , the alphabet, is the same as in M ​​1 and M 2 . In this theorem and all subsequent similar theorems, we assume for simplicity that both M 1 and M 2 have the same input alphabet Σ . The theorem remains true if both used different alphabets, Σ 1 and Σ 2 . We would then only have to modify the proof by assuming that Σ = Σ 1 Σ 2 .
  5. 我们将传递函数δ定义如下。对于每对 ( r 1 , r 2 ) Q和每个a Σ,令

    δ (( r 1 , r 2 ), a ) = ( δ 1 ( r 1 , a ), δ 2 ( r 2 , a ))。

    因此δ接受状态M (本质上是来自M 1M 2的一对状态)以及输入符号,并返回机器M的下一个状态。

  6. The transition function δ is defined as follows. For each pair ( r 1 , r 2 ) Q and each a Σ , let

    δ (( r 1 , r 2 ), a ) = ( δ 1 ( r 1 , a ), δ 2 ( r 2 , a )).

    So δ takes a state M (which is really a pair of states from M 1 and M 2 ) along with an input symbol and returns the next state of the machine M .

  7. q 0是对( q 1 , q 2 )。
  8. q 0 is a pair ( q 1 , q 2 ).
  9. F是其中任何元素是接受M 1M 2的状态的对的集合。

    我们可以把它写成

  10. F is the set of pairs in which any of the elements is a state accepting M 1 or M 2 .

    We can write this as

F = {( r 1 , r 2 ) : r 1 F 1r 2 F 2 }。

F = {( r 1 , r 2 ) : r 1 F 1 or r 2 F 2 }.

该表达式等价于F = ( F 1 × Q 2 ) ( Q 1 × F 2 )。 (请注意,这与F = F 1 × F 2不同。在这种情况下我们会得到什么?3

This expression is equivalent to F = ( F 1 × Q 2 ) ( Q 1 × F 2 ). (Note that this is not the same as F = F 1 × F 2 . What would we get in that case? 3 )

这就完成了识别语言A 1A 2之和的有限自动机M的构造。这种结构非常简单,因此其正确性显然来自于证明概念中描述的策略。更复杂的结构需要额外的讨论来证明其有效性。此类结构的正确性的正式证明通常是通过归纳法进行的。证明该结构正确性的一个例子可以在定理 1.54 的证明中找到。我们在本书中遇到的大多数结构都相对简单,因此不需要正式的正确性证明。

This completes the construction of the finite automaton M , which recognizes the union of the languages ​​A 1 and A 2 . This construction is quite simple, and thus its correctness follows obviously from the strategy described in the proof concept. More complex constructions require additional discussion to show their correctness. A formal proof of correctness for constructions of this type is usually carried out by induction. An example of a proof of the correctness of a construction can be found in the proof of Theorem 1.54. Most of the constructions we will encounter in this book are relatively simple and as such do not require a formal proof of correctness.

我们刚刚证明了两种正则语言的并集是正则语言,因此我们证明了正则语言的类对于并集运算是封闭的。我们现在将处理连接操作,并尝试表明正则语言的类也因该操作而封闭。

We have just shown that the union of two regular languages ​​is a regular language, and thus we have proved that the class of regular languages ​​is closed under the union operation. We now turn to the concatenation operation and try to show that the class of regular languages ​​is also closed under this operation.

定理1.26

Theorem 1.26

正则语言的类由于串联操作而被封闭。

The class of regular languages ​​is closed under the concatenation operation.

换句话说,如果A 1A 2是正则语言,那么A 1 A 2也是正则语言。

In other words, if A 1 and A 2 are regular languages, then A 1 A 2 is also regular .

为了证明这个定理,我们可以使用类似于求和情况的证明。和之前一样,我们将从有限自动机M 1M 2开始,识别正则语言A 1A 2。然而,这一次,不是构造一个机器M ,当M 1M 2接受输入字时,该机器必须接受输入数据是否可以分为两部分,使得M 1接受第一个部分,并且M2接受其中的第二个问题是M不知道在哪里分割输入数据(即第一部分在哪里结束,第二部分在哪里开始)。为了解决这个问题,我们引入了一种称为非确定性的新技术。

To prove this theorem, we can use something similar to the proof for the sum case. As before, we start with finite automata M 1 and M 2 , recognizing regular languages ​​A 1 and A 2 . This time, however, instead of constructing an automaton M that accepts its input whenever either M 1 or M 2 would accept it, the automaton must accept if the input can be split into two parts such that M 1 accepts the first and M 2 accepts the second. The problem is that M does not know where to split the input (that is, where the first part ends and the second begins). To solve this problem, we introduce a new technique called nondeterminism.

1.2

非决定论

1.2

Nondeterminism

非确定性是一个有用的概念,对计算理论产生了很大的影响。到目前为止,在我们的考虑中,每一步的计算都清楚地来自前一步。当机器处于某种状态并读取下一个输入符号时,我们知道它的下一个状态将是什么——它是确定的。我们称之为确定性计算。在非确定性机器中,每个点的下一个状态可以有多种选择。

Nondeterminism is a useful concept that has had a profound impact on the theory of computation. So far, in our discussion, each step of a computation has been a unique consequence of the step before it. When the machine is in a certain state and reads the next input symbol, we know what its next state will be—this is determined. We call this deterministic computation . In a nondeterministic machine, at each point there can be several choices for the next state.

非确定性是确定性的推广,因此每个确定性有限自动机都是非确定性有限自动机。如图 1.27 所示,非确定性有限状态机可以具有其他属性。

Nondeterminism is a generalization of determinism, so every deterministic finite automaton is a nondeterministic finite automaton. As shown in Figure 1.27, nondeterministic finite automatons can have additional properties.

1.27

非确定性有限状态机N 1

Figure 1.27

Nondeterministic finite automaton N 1

确定性有限自动机( DFA)和非确定性有限自动机(非确定性有限自动机,NFA)之间的区别乍一看是显而易见的。首先,每个 DFA 状态对于每个字母符号始终只有一个传出转换。图 1.27 所示的 NFA 违反了这一规则。状态q 1对于0有一个传出转换,但对于1有两个传出转换;q 2有一个0 的传出转换,但没有1 的传出转换。在 NFA 中,对于字母表中的每个符号,状态可以有零个、一个或多个传出转换。

The difference between a deterministic finite automaton (DFA) and a nondeterministic finite automaton (NFA) is obvious at first glance. First, each state of a DFA always has exactly one outgoing transition for each symbol of the alphabet. The NFA shown in Figure 1.27 violates this rule. State q 1 has one outgoing transition for 0 but two for 1 ; q 2 has one outgoing transition for 0 but none for 1 . In an NFA, a state can have zero, one, or many outgoing transitions for each symbol of the alphabet.

其次,在 DFA 中,描述转换箭头的标签是字母表中的符号。然而,该 NFA 包含一个标记为ε 的箭头。一般来说,NFA 可能包含由字母元素或ε描述的多个转换。每个状态可以产生零个、一个或多个用标签ε标记的转换(为了简化符号,我们将它们称为ε -转换)。

Second, in a DFA, the labels describing the transition arrows are symbols from the alphabet. However, this NFA contains an arrow labeled ε . In general, an NFA can contain many transitions labeled with elements of the alphabet or ε . Each state can give rise to zero, one, or many transitions labeled ε (for simplicity, we will call them ε -transitions).

NFA 中如何进行处理?假设我们对某个输入词运行 NFA,并到达有几条进一步路径的状态。例如,假设我们处于状态q 1 NFA N 1,下一个输入符号是1。读完这个符号后,机器会分裂成许多自身的副本,并并行地追求每种可能性。机器的每个副本都采用可能的路径之一并继续运行。如果出现后来的选择,机器会再次分裂。如果下一个输入符号没有出现在任何离开机器给定副本状态的转换中,则该副本与相应的处理分支一起“死亡”。最后,如果在输入结束时机器的任何剩余副本处于接受状态,则 NFA 接受输入字。

How does processing in NFA work? Suppose we run NFA for some input word and arrive at a state where there are several possible paths. For example, let's say we are in state q 1 NFA N 1 and that the next input symbol is 1 . After reading this symbol, the machine splits into multiple copies of itself and pursues each of the possibilities in parallel. Each copy of the machine takes one of the possible paths and continues. If there are later choices, the machine splits again. If the next input symbol does not occur in any of the transitions out of the state of a given copy of the machine, then that copy "dies" along with its corresponding processing branch. Finally, if at the end of the input data any of the remaining copies of the machine is in an accepting state, then the NFA accepts the input word.

如果在传出转换时遇到带有符号ε的状态,则会发生类似的情况。在不读取下一个输入符号的情况下,机器会在每次传出ε转换后分裂成许多副本,并在当前状态中保留一个副本。然后机器像以前一样执行进一步的非确定性处理。

If a state with symbol ε is encountered on an outgoing transition, something similar happens. Without reading another input symbol, the machine splits into multiple copies following each of the outgoing ε -transitions, plus one more remaining in the current state. The machine then performs further nondeterministic processing as before.

非确定性可以被视为一种并行处理,其中可以同时执行多个独立的“进程”或“线程”。当 NFA 拆分以遵循多个选择时,这对应于“分支”为多个子进程,每个子进程单独执行。如果这些进程之一达到接受状态,则所有处理都在接受。

Nondeterminism can be viewed as a type of parallel processing in which multiple independent "processes" or "threads" can execute simultaneously. When an NFA splits to follow multiple choices, this corresponds to "branching" into multiple child processes, each executing separately. If even one of these processes enters an accepting state, the entire processing is accepting.

思考非确定性处理的另一种方法是可能性树的想法。树的根对应于计算的开始。树中的每个分支点对应于机器有多种选择的点。如果至少一个处理分支以接受状态结束,则机器接受,如图 1.28 所示。

Another way to think about nondeterministic computing is in terms of a tree of possibilities. The root of the tree corresponds to the beginning of the computation. Each branching point in the tree corresponds to a point where the machine has several choices. The machine accepts if at least one of the branches of processing ends in an accepting state, as in Figure 1.28.

1.28

接受分支的确定性和非确定性处理

Figure 1.28

Deterministic and nondeterministic processing with an accept branch

1.29 N1

中对输入字 010110 的处理

Figure 1.29

Processing in N1 for input word 010110

考虑图 1.27 中所示的NFA N 1的一些示例运行。输入字010110的N 1处理如下图所示。

Consider some sample NFA N 1 runs shown in Figure 1.27. The processing of N 1 for input word 010110 is shown in the figure below.

对于输入字010110,我们从初始状态q 1开始并读取第一个符号0。对于0,从状态q 1只有一个地方可以去- 具体来说,状态q 1本身- 所以我们留在那里。然后我们读取第二个符号1。在状态q 1中,符号1有两个选择:保持在q 1或移动到q 2。机器以非确定性方式运行,分成两部分并遵循其中的每一个选择。我们可以通过观察机器可能处于的每个状态来跟踪这些可能性。所以我们已经掌握了状态q 1q 2q 2状态出现ε跃迁,机器再次分裂;我们将手指放在 q 2上,并将另一根手指放在q 3上。所以我们已经掌握了q 1q 2q 3

For input word 010110, we start in the initial state q 1 and read the first symbol 0 . For 0, there is only one place to go from state q 1 —namely, state q 1 itself —so we stay there. Then we read the second symbol 1 . In state q 1 , symbol 1 has two choices: staying in q 1 or going to q 2 . Operating nondeterministically, the machine splits in two and follows each of these choices. We can keep track of these possibilities by placing fingers on each state the machine could be in. So we have fingers on states q 1 and q 2 . From state q 2 comes an ε -transition and the machine splits again; we keep a finger on state  q 2 and another on q 3 . So we have fingers on q 1 , q 2 , and q 3 .

读取第三个符号0后,我们依次检查每个手指。我们将状态q 1的手指留在原处,将手指从状态q 2移动到q 3并拿走处于状态q 3的手指。对于后者,没有标签0 的转换跟随;这对应于一个简单地“死亡”的进程。此时,我们已经掌握了状态q 1q 3

After reading the third symbol, 0 , we check each finger in turn. We leave the finger in state q 1 in place , move the finger in state q 2 to q 3 , and take away the one that was in state q 3 . For the latter, there was no transition with label 0 to follow; this corresponds to a process that simply "died." At this point, we have fingers in states q 1 and q 3 .

读完第四个符号1 后,我们将停留在q 1上的手指分成状态q 1q 2上的手指,然后进一步将q 2中的手指分裂为遵循ε转移到q 3,并且是的手指到目前为止,在q 3上,我们转向q 4。我们现在已经掌握了这四个州的情况。

After reading the fourth symbol, 1 splits the finger resting on q 1 into fingers on states q 1 and q 2 , then further splits the finger from q 2 to follow the ε -transition to q 3 , and moves the finger that was on q 3 to q 4 . We now have fingers on each of the four states.

当我们读取第五个符号1时,处于状态q 1q 3 的手指导致处于状态q 1q 2q 3q 4的手指,就像第四个符号的情况一样。状态q 2的手指被移除。位于q 4上的手指仍位于q 4上。现在我们有两个手指放在q 4上,所以我们可以移除一个手指,因为我们只需要记住q 4此时是一种可能的状态,而不是由于多种原因它是可能的。

When we read the fifth symbol 1 , the fingers at states q 1 and q 3 result in fingers at states q 1 , q 2 , q 3 , and q 4 , just as in the case of the fourth symbol. The finger at state q 2 is removed. The finger that was on q 4 remains on q 4 . We now have two fingers at q 4 , so we can remove one, since we only need to remember that q 4 is a possible state at this point, not that it is possible for multiple reasons.

读取第六个也是最后一个符号0 后,我们将q 1上的手指留在原处,将状态q 2移动到q 3 ,移除q 3上的手指,状态q 4上的手指保持在原位。我们处于单词的末尾,如果其中一根手指处于接受状态,我们可以说机器接受它。手指停留在状态q 1q 3q 4上;由于q 4是接受状态,因此自动机N 1接受该词。

After reading the sixth and last symbol 0 , we leave the finger on q 1 in place, move the one from state q 2 to q 3 , remove the one that was on q 3 , and the finger from state q 4 remains in place. We have reached the end of the word and can say that the automaton accepts it if any of the fingers is in the accepting state. The fingers rest on states q 1 , q 3 , and q 4 ; and since q 4 is the accepting state, the automaton N 1 accepts the word.

N 1对输入010有何作用?我们从q 1上的手指开始。读取0后,我们仍然只有一根手指放在q 1上;然而,在1之后,我们将关注状态q 1q 2q 3(我们不能忘记ε转变)。在第三个0符号之后,我们将手指从q 3移开,将手指从q 2移动到q 3 ,而q 1上的手指保持在原来的位置。此时,我们处于输入字的末尾,并且由于没有手指处于接受状态,因此N 1丢弃该数据。

What will N 1 do for input 010 ? We start with a finger on q 1 . After reading 0 , we still have a finger only on q 1 ; however, after 1, we will have fingers on states q 1 , q 2 , and q 3 (we cannot forget the ε -transition). After the third symbol 0 , we remove the finger from q 3 , move the finger from q 2 to q 3 , and the finger on q 1 stays where it is. At this point, we are at the end of the input word, and since none of the fingers have entered an accepting state, N 1 discards the data.

继续这样实验,我们可以看到N 1接受所有包含10111的单词作为子词。

Continuing to experiment in this way, we can see that N 1 accepts all words that contain 101 or 11 as a subword.

出于多种原因,非确定性有限状态机很有用。正如我们稍后将展示的,任何 NFA 都可以转化为等效的 DFA,并且构建 NFA 有时比直接构建 DFA 更容易。 NFA 可能比其确定性对应物小得多,或者其功能可能更容易理解。有限自动机中的非确定性也是在更强大的计算模型中使用非确定性的一个很好的介绍,因为有限自动机特别容易理解。我们现在将展示 NFA 的一些示例。

Nondeterministic finite automata are useful for many reasons. As we will show later, any NFA can be transformed into an equivalent DFA, and constructing an NFA is sometimes easier than constructing a DFA directly. An NFA can be much smaller than its deterministic counterpart, or its functioning can be easier to understand. Nondeterminism in finite automata is also a good introduction to the use of nondeterminism in stronger models of computation, since finite automata are particularly easy to understand. We will now show some examples of NFAs.

1.30

Example 1.30

A是字母表 { 0 , 1 } 上的一种语言,由所有在倒数第三个位置包含1 的单词组成(例如000100属于A,而0011不属于 A )。以下四状态 NFA N2认可A.

Let A be a language over the alphabet { 0 , 1 }, consisting of all words containing 1 in the third last position (i.e., 000100 is a member of A , while 0011 is not). The following four-state NFA N 2 recognizes A .

1.31

NFA N 2识别语言A

Figure 1.31

NFA N 2 recognizing language A

您可以想象该 NFA 执行的处理方式是,它保持在状态q 1,直到它“猜测”它已经是倒数第三个了。只有当输入符号为1时,它才会移动到状态q 2,然后使用状态q 3q 4来“检查”这个猜测是否正确。

The processing performed by this NFA can be imagined as being in state q 1 until it “guesses” that it is already in the third position from the end. Only when the input symbol is 1 does it move to state q 2 , at which point it uses states q 3 and q 4 to “check” whether that guess was correct.

正如我们之前提到的,任何 NFA 都可以转换为等效的 DFA,但有时该 DFA 的状态要多很多倍。识别语言A的最小DFA包含八个状态。此外,理解 NFA 的工作原理要容易得多,如下图所示,显示了等效的 DFA。

As we mentioned earlier, any NFA can be converted to an equivalent DFA, but sometimes this DFA has many times more states. The smallest DFA recognizing language A contains eight states. Moreover, understanding the operation of NFA is much easier, as can be seen in the figure below showing an equivalent DFA.

1.32

DFA识别语言A

Figure 1.32

DFA recognizing language A

假设我们将ε添加到图 1.31 的N 2机器中从q 2q 3以及从 q 3q 4 的转换标签中。因此,两者都将具有标签01ε而不仅仅是01。修改后N 2能识别什么语言?尝试修改图 1.32 中的 DFA 来识别这种语言。

Suppose we have added ε to the labels of the transitions from q 2 to q 3 and from  q 3 to q 4 in the machine N 2 of Figure 1.31. Thus, both will have labels 0 , 1 , ε instead of just 0 , 1 . What language will N 2 recognize after this modification? Try to modify the DFA of Figure 1.32 so that it recognizes this language.

1.33

Example 1.33

下面所示的NFA N 3具有由单个符号组成的输入字母表 { 0 }。仅包含一个符号的字母表称为一元字母表

The NFA N 3 shown below has an input alphabet { 0 } consisting of a single symbol. An alphabet containing only one symbol is called a unary alphabet .

1.34

NFA N 3

Figure 1.34

NFA N 3

该机器展示了使用ε跃迁的便利性。它接受0 k形式的所有单词,其中k是 2 或 3 的倍数。(回想一下,在单词的情况下,上标表示重复,而不是数字的幂)。例如, N 3接受单词ε000000000000000,但不接受000000

This machine demonstrates the convenience of using ε -transitions. It accepts all words of the form 0 k , where k is a multiple of 2 or 3. (Recall that in the case of words, the superscript denotes repetition, not exponentiation.) For example, N 3 accepts the words ε , 00 , 000 , 0000 , and 000000 , but not 0 or 00000 .

你可以想象这台机器是如何工作的,首先猜测是测试 2 的倍数还是 3 的倍数,选择顶部或底部循环,然后检查哪个猜测是正确的。当然,我们可以用没有ε转换或根本没有不确定性的机器来替换这台机器,但是所示的机器是所有识别这种语言的机器中最容易理解的。

The operation of this machine can be imagined as first guessing whether to test for a multiple of 2 or a multiple of 3, choosing either the upper or lower loop, and then checking which guess was correct. Of course, we could replace this machine with one that contains no ε -transitions or any nondeterminism at all, but the machine shown is the easiest to understand of all the automata that recognize this language.

1.35

Example 1.35

NFA 的另一个示例如图 1.36 所示。请随意练习,看看它会接受单词εabababaa,但不会接受单词bbbbabba。稍后我们将使用这台机器来说明将 NFA 转换为 DFA 的过程。

Another example NFA is shown in Figure 1.36. We encourage you to practice on it to see that it will accept the words ε , a , baba , and baa , but will not accept the words b , bb , or babba . We will later use this machine to illustrate the procedure for converting an NFA to a DFA.

1.36

NFA N 4

Figure 1.36

NFA N 4

非确定性有限自动机的形式定义

Formal definition of a nondeterministic finite automaton

非确定性有限自动机的形式定义类似于前面提出的确定性自动机的定义。两者都有一组状态、一个输入字母表、一个转换函数、一个初始状态和一组接受状态。然而,它们在一个关键方面有所不同。在 DFA 中,转换函数采用一个状态和一个输入符号并返回下一个状态。在 NFA 中,转换函数采用一个状态和一个输入符号或空字,并返回一组可能的下一个状态。为了能够编写正式的定义,我们需要引入额外的符号。对于任何集合Q,我们将使用符号P (Q)作为Q的所有子集的集合。集合P (Q)称为幂 Q。对于任何字母表Σ,我们将使用符号Σ ε来表示Σ { ε }。现在我们可以将 NFA 中传递函数类型的形式形式写为δ : Q × Σ εP (Q)

The formal definition of a nondeterministic finite state machine is analogous to the definition of a deterministic finite state machine presented earlier. Both have a set of states, an input alphabet, a transition function, an initial state, and a set of accepting states. However, they differ in one key respect. In a DFA, the transition function takes a state and an input symbol and returns the next state. In an NFA, the transition function takes a state and an input symbol or an empty word and returns the set of possible next states . To be able to write the formal definition, we need to introduce some additional notation. For any set Q, we will use the notation P (Q) as the set of all subsets of Q . The set P (Q) is called the power set of Q . For any alphabet Σ, we will use the notation Σ ε to denote Σ { ε }. We can now write the formal form of the type of the transition function in an NFA as δ : Q × Σ εP (Q) .

定义 1.37

Definition 1.37

非确定性有限自动机称为有序五 ( Q , Σ , δ , q 0 , F ),其中

A nondeterministic finite automaton is an ordered five ( Q , Σ , δ , q 0 , F ), where

  1. Q是有限状态集,
  2. Q is a finite set of states,
  3. Σ是有限字母表,
  4. Σ is a finite alphabet,
  5. δ : Q × Σ εP (Q)是传递函数,
  6. δ : Q × Σ εP (Q) is the transition function,
  7. q 0 Q是初始状态,并且
  8. q 0 Q is the initial state, and
  9. F Q是接受状态的集合。
  10. F Q is the set of accepting states.

1.38

Example 1.38

让我们回忆一下 NFA N 1

Let's recall NFA N 1 :

N 1的形式化描述为 ( Q , Σ , δ , q 0 , F ),其中

The formal description of N 1 is ( Q , Σ , δ , q 0 , F ), where

  1. Q = { q 1 , q 2 , q 3 , q 4 },
  2. Q = { q 1 , q 2 , q 3 , q 4 },
  3. Σ = { 0 , 1 },
  4. Σ = { 0 , 1 },
  5. δ定义为

    0

    1

    Ε

    q 1

    { q 1 }

    { q 1 , q 2 }

    关于

    q 2

    { q 3 }

    关于

    { q 3 }

    q 3

    关于

    { q 4 }

    关于

    q 4

    { q 4 }

    { q 4 }

    关于

  6. δ is defined as

    0

    1

    Ε

    q1

    { q 1 }

    { q1 , q2 }

    ABOUT

    q2

    { q 3 }

    ABOUT

    { q 3 }

    q3

    ABOUT

    { q 4 }

    ABOUT

    q4

    { q 4 }

    { q 4 }

    ABOUT

  7. q 1是初始状态,并且
  8. q 1 is the initial state, and
  9. F = { q 4 }。
  10. F = { q 4 }.

NFA 计算的正式定义与 DFA 类似。令N = ( Q , Σ , δ , q 0 , F ) 为 NFA ,w为字母表Σ上的一个单词。然后,如果我们可以将w写为w = y 1 y 2 …y m ,则我们说N 接受 w,其中每个y i是Σ ε的元素,并且存在一系列状态r 0 , r 1 , …, r m属于Q,满足三个条件:

The formal definition of computation for NFA is analogous to that for DFA. Let N = ( Q , Σ , δ , q 0 , F ) be an NFA, and w be a word over the alphabet Σ . We then say that N accepts w if we can write w as w = y 1 y 2 …y m , where each y i is an element of Σ ε and there is a sequence of states r 0 , r 1 , …, r m belonging to Q , satisfying three conditions:

  1. r 0 = q 0
  2. r 0 = q 0 ,
  3. r i +1 δ ( r i , y i +1 ) 对于i = 0, …, m − 1, 并且
  4. r i +1 δ ( r i , y i +1 ) for i = 0, …, m − 1, and
  5. r m F
  6. r m F .

条件 1 表明机器在初始状态下启动。条件 2 表明,当机器N处于状态r i并读取符号y i +1时,状态r i +1是允许的下一个状态之一。请注意,δ ( r i , y i +1 ) 是允许的下一个状态的集合,并且我们要求r i +1是该集合的元素。最后,条件 3 表明如果最后一个状态是接受状态,则机器接受输入字。

Condition 1 states that the machine starts in the initial state. Condition 2 states that state r i +1 is one of the legal next states if machine N is in state r i and reads the symbol y i +1 . Note that δ ( r i , y i +1 ) is the set of legal next states, and that we require r i +1 to be an element of this set. Finally, condition 3 states that the machine accepts an input word if the last state is an accepting state.

NFA 和 DFA 的等价性

Equivalence of NFA and DFA

确定性和非确定性有限自动机识别同一类语言。这种等价性既令人惊讶又有用。这令人惊讶,因为 NFA 似乎比 DFA 更通用,因此我们期望它们能够识别更多语言。它很有用,因为描述给定语言的 NFA 有时比描述该语言的 DFA 容易得多。

Deterministic and nondeterministic finite automata recognize the same class of languages. This equivalence is both surprising and useful. It is surprising because it might seem that NFAs are more universal than DFAs, so we might expect them to recognize more languages. It is useful because describing an NFA for a given language is sometimes much easier than describing a DFA for that language.

如果两台机器识别相同的语言,我们就说它们是等价的。

We say that two machines are equivalent if they recognize the same language.

定理1.39

Theorem 1.39

对于每个非确定性有限自动机,都有一个等效的确定性有限自动机。

For every nondeterministic finite automaton there is a corresponding equivalent deterministic finite automaton.

证明的概念 如果一种语言被 NFA 识别,我们必须证明存在也识别它的 DFA。这个想法是将 NFA 转换为模拟该 NFA 的等效 DFA。

Proof Concept If a language is recognized by an NFA, we need to show the existence of a DFA that also recognizes it. The idea is to transform the NFA into an equivalent DFA that will simulate this NFA.

让我们回顾一下设计有限自动机的“读者作为自动机”策略。如果我们冒充 DFA,如何模拟 NFA?在处理输入单词时,您需要跟踪什么?在所示的 NFA 示例中,我们通过将手指放在可能在特定点处于活动状态的每个状态来跟踪计算的各个分支。我们根据 NFA 的工作原理通过移动、添加或移除手指来更新模拟。我们所需要跟踪的只是一组“手指”状态。

Recall the reader-as-automaton strategy of finite-state automata design. How could we simulate an NFA if we pretended to be a DFA? What would need to be kept track of as the input word was processed? In the NFA examples shown, we kept track of the various branches of the computation by placing fingers on each state that might be active at a given point. We updated the simulation by moving, adding, or removing fingers in accordance with the way the NFA works. All we had to keep track of was the set of states “with fingers.”

如果k是 NFA 状态的数量,则这些状态有 2 k个子集。每个子集对应于 DFA 必须记住的一种可能性,因此模拟 NFA 的 DFA 将有 2k 个状态。现在我们需要确定正在创建的 DFA 的初始状态和接受状态集以及其转换函数是什么。一旦正式写成,这将更容易讨论。

If k is the number of states of the NFA, then there are 2 k subsets of these states for it . Each subset corresponds to one of the possibilities that the DFA must remember, so a DFA simulating the NFA will have 2 k states. Now we need to determine the initial state and the set of accepting states of the DFA being created, and what its transition function will be. This will be easier to discuss once we have introduced a formal notation.

证明N =( Q , Σ , δ , q 0 , F ) 是一个识别某种语言A 的NFA 。我们将构造一个识别A的DFA M = ( Q' , Σ , δ' , q 0 ' , F' ) 。在执行完整的构造之前,让我们考虑一个更简单的情况,其中N不包含带有标签ε的转换。稍后我们还将考虑此类ε跃迁。

Proof Let N = ( Q , Σ , δ , q 0 , F ) be an NFA recognizing some language A . We construct a DFA M = ( Q' , Σ , δ' , q 0 ' , F' ) recognizing A . Before doing the full construction, let us consider the simpler case in which N does not contain transitions with labels ε . Later we will consider such ε -transitions as well.

  1. Q' = P (Q)

    每个状态M都是N的状态集合。回想一下,P (Q)是Q的所有子集的集合。

  2. Q' = P (Q) .

    Each state of M is a set of states of N . Recall that P (Q) is the set of all subsets of Q .

  3. 对于R ε Q'a ε Σ,δ' ( R , a ) = { q ε Q : q ε δ ( r , a ) 对于某些r ε R }。

    如果R是M 的状态,那么它也是N的状态集合。当M在状态R中读取符号时,这表明属于R的每个状态将被转移到哪里。由于每个状态都可以遍历到可能状态的集合,因此我们对所有这些状态进行并集。该表达式的另一种写法可以是4

  4. For R Q' and a Σ let δ' ( R , a ) = { q Q : q δ ( r , a ) for some r R }.

    If R is a state of M , then it is also the set of states of N . When M reads a symbol while in state R , it shows where each state in R will go . Since each state can go to the set of possible states, we perform the union of all these states. Another way to write this expression could be 4

  5. q 0 ' = { q 0 }。

    M开始时的状态对应于仅包含初始状态N的集合。

  6. q0 ' = { q0 } .

    M starts in the state corresponding to the collection containing only the initial state N .

  7. F' = { R Q' : R包含接受N 的状态}。

    如果机器M 此时可能处于的可能状态N之一是接受状态,则机器M接受。

  8. F' = { R Q' : R contains a state accepting N }.

    A machine M accepts if one of the possible states N that it can be in at that moment is an accepting state.

现在我们需要考虑ε跃迁。为此,我们需要一些额外的符号。对于M的任何状态R ,我们将E ( R ) 定义为仅通过遵循ε转移即可从R 的元素到达的状态集合,包括R的元素本身。形式上我们可以这样写:对于R QE ( R ) = { q : q可以通过以下 0 个或多个ε -转换从R到达q 。

Now we need to include ε -transitions. To do this, we need some additional notation. For any state R of M, we define E ( R ) to be the collection of states that can be reached from elements of R by following only ε -transitions, including elements of R itself . Formally, we can write this: for R Q , let E ( R ) = { q : q can be reached from R by following 0 or more ε -transitions}.

现在我们可以修改机器M的转换函数,在每一步之后将额外的手指放置在ε转换可到达的所有状态上。我们通过将δ ( r , a ) 更改为E ( δ ( r , a )) 来得到这一点。意思是

Now we can modify the transition function of the automaton M so as to place additional fingers on all states reachable by ε -transitions after each step. We achieve this by changing δ ( r , a ) to E ( δ ( r , a )). Thus

δ' ( R , a ) = { q Q : q E ( δ ( r , a )) 对于某些r R }。

δ' ( R , a ) = { q Q : q E ( δ ( r , a )) for some r R }.

此外,我们需要修改初始状态M ,以将手指初始放置在从初始状态N沿ε转换可以到达的所有可能状态上。将q 0 '替换为E ({ q 0 }) 可提供此效果。因此,我们已经完成了模拟 NFA N的 DFA M的构建。

In addition, we need to modify the initial state M to initially place fingers on all possible states that can be reached from the initial state N along ε -transitions. Replacing q 0 ' with E ( { q 0 } ) provides this effect. We have thus completed the construction of the DFA M , which simulates the NFA N .

M设计显然工作正常。在每个输入处理步骤中,M进入与N在该点应处于的状态子集相对应的状态。这样我们的证明就完成了。

The construction of M clearly works correctly. At each input processing step, M enters the state that corresponds to a subset of the states that N should be in at that point. This completes our proof.

定理 1.39 指出任何 NFA 都可以转化为其等价的 DFA。因此,非确定性有限自动机是表征正则语言的另一种方法。我们将这一事实表述为定理 1.39 的结论。

Theorem 1.39 states that every NFA can be transformed into an equivalent DFA. Thus, nondeterministic finite automata are an alternative way of characterizing regular languages. We will formulate this fact as a corollary of Theorem 1.39.

应用1.40

Motion 1.40

当且仅当一种语言被某种非确定性有限自动机识别时,它才是正则语言。

A language is regular if and only if it is recognized by some nondeterministic finite automaton.

“当且仅当”条件的一个方向表明,如果某种语言被某些 NFA 识别,则该语言是正则语言。定理 1.39 表明任何 NFA 都可以转换为等效的 DFA。因此,如果 NFA 识别某种语言,某种 DFA 也会识别,因此该语言是正则的。 “当且仅当”条件的第二个方向认为,只要某种语言被某个 NFA 识别,它就是正则语言。换句话说,如果一种语言是正则语言,那么就有一些 NFA 可以识别它。这个条件显然是满足的,因为每个正则语言都有一个可以识别它的 DFA,并且每个 DFA 也是一个 NFA。

One direction of the if-and-only-if condition states that a language is regular if it is recognized by some NFA. Theorem 1.39 shows that every NFA can be converted into an equivalent DFA. So if an NFA recognizes a language, then so does some DFA, and hence that language is regular. The other direction of the if-and-only-if condition states that a language is regular if it is recognized by some NFA. In other words, if a language is regular, then there is some NFA that recognizes it. This condition is obviously satisfied, since every regular language has a DFA that recognizes it, and every DFA is also an NFA.

1.41

Example 1.41

让我们尝试使用例 1.35 中所示的N 4机器来说明定理 1.39 的证明中所示的 NFA 到 DFA 的转换过程。为了清楚起见,我们将机器N 4的状态标签更改为 {1, 2, 3}。因此,在形式化表示中,N 4 = ( Q , {a, b }, δ , 1, {1}),其中状态集合Q是集合 {1, 2, 3},如图 1.42 所示。

Let us illustrate the procedure for converting NFA to DFA, given in the proof of Theorem 1.39, using the N 4 machine shown in Example 1.35. For clarity, we have changed the labels of the states of N 4 to {1, 2, 3}. Thus, in formal notation, N 4 = ( Q , {a, b }, δ , 1, {1}), with the set of states of Q being {1, 2, 3}, as shown in Figure 1.42.

为了构造一个等价于N 4的DFA D ,我们必须首先定义D的状态。 N 4具有三个状态 {1, 2, 3},因此我们将构造具有八个状态的D,每个状态对应N 4状态的每个子​​集。我们将描述每个状态D及其相应的子集。因此,状态集D

To construct a DFA D that is equivalent to N 4 , we first need to determine the states of D . N 4 has three states, {1, 2, 3}, so we will construct D with eight states, one for each subset of the states of N 4 . We will describe each state of D by its corresponding subset. Thus, the set of states of D is

{ Ø , {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}}。

{ Ø , {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}}.

1.42

NFA N 4

Figure 1.42

NFA N 4

然后我们确定初始状态和接受状态D。初始状态是集合E ({1}),即从状态1通过ε-转移和状态1本身可到达的状态集合; ε跃迁从 1 引导至 3,因此E ({1}) = {1, 3}。新的接受状态是包含N 4台机器的接受状态的子集。因此,它是集合{{1}, {1,2}, {1,3}, {1,2,3}}。

Next, we establish the initial state and the accepting states D . The initial state is the set E ({1}), i.e. the set of states reachable from state 1 via ε -transitions and state 1 itself; the ε -transition leads from 1 to 3, so E ({1}) = {1, 3}. The new accepting states are those subsets that contain an accepting state of the machine N 4 . This is therefore the set {{1}, {1,2}, {1,3}, {1,2,3}}.

最后,我们需要确定D的传递函数。每个状态D都会导致一个输入a的位置和一个输入b的位置。我们将使用几个例子来说明D中安排转换的过程。

Finally, we need to define a transition function for D . Each state of D leads to one location for input a and one for input b . We will illustrate the process of arranging transitions in D with several examples.

在机器D 中,状态 {2} 导致输入a的 {2,3} ,因为在N 4中,状态 2 导致输入a的状态 2 和 3 ,并且我们无法从状态 2 和 3 进一步沿着ε转换。对于输入b,状态 {2} 会导致状态 {3} ,因为在N 4中,对于输入b,状态 2 只能转换到状态 3 ,并且我们无法沿着ε转换从状态 3 进一步前进。

In automaton D, state {2} leads to state {2,3} for input a , because in N 4 state 2 leads to both states 2 and 3 for input a and we cannot go any further from states 2 and 3 along ε -transitions. State {2} leads to state {3} for input b , because in N 4 state 2 has a transition only to state 3 for input b and we cannot go anywhere further from state 3 along ε -transitions.

输入a 的状态 {1}导致Ø,因为N 4中的状态 1没有带有标签a 的传出转换。反过来,对于b,它会导致状态 {2}。请注意,定理 1.39 中描述的过程指定我们在读取每个输入符号后遵循ε转换。基于在读取每个输入符号之前遵循ε转换原则的替代过程也同样有效,但我们不会在本示例中对其进行说明。

State {1} for input a leads to Ø , since state 1 in N 4 has no outgoing transitions with label a . On the other hand, for b it leads to state {2}. Note that the procedure described in Theorem 1.39 specifies that we follow the ε -transitions after reading each input symbol. An alternative procedure based on following the ε -transitions before reading each input symbol would work equally well, but we will not illustrate it in this example.

对于a ,状态 {3} 会导致状态 {1,3} ,因为在N 4中,对于a,状态 3 会过渡到 1 ,并且可以通过ε过渡从 1 过渡到 3。b的状态 {3}导致Ø

State {3} leads to state {1,3} for a , since in N 4 state 3 has a transition to 1 for a , and from 1 it is possible to transition to 3 via an ε -transition. State {3} for b leads to Ø .

a的状态 {1,2}转换为 {2,3},因为 1 对于该输入没有转换,2 指向a的状态 2 和 3 ,并且它们都没有进一步的ε转换。对于b,状态 {1,2} 导致 {2,3}。继续这样,我们得到如图1.43所示的机器D的图。

The state {1,2} for a has a transition to {2,3}, since 1 has no transitions for this input, 2 indicates for a both states 2 and 3 and neither of them has any further ε -transitions. For b the state {1,2} leads to {2,3}. Continuing in this way, we obtain the diagram of the automaton D shown in Figure 1.43.

1.43

DFA D相当于NFA N 4

Figure 1.43

DFA D equivalent to NFA N 4

我们可以通过注意到没有任何转换导致状态 {1} 和 {1, 2} 来简化该机器,因此可以在不影响机器效率的情况下删除它们。这样我们就得到了下面的图。

We can simplify this machine by noting that no transitions lead to states {1} and {1, 2}, so they can be removed without affecting the efficiency of the machine. This gives us the following figure.

1.44去除不必要状态后的

DFA D

Figure 1.44

DFA D after removing unnecessary states

暂停正常运营

Closure due to regular operations

我们现在可以回到我们在 1.1 节中开始讨论的由于正则操作而关闭正则语言类的问题。我们的目标是证明正则语言并集、串联和 Kleene 闭包仍然是正则的。当发现串联操作太复杂而无法处理时,我们放弃了最初的尝试。使用非决定论将使证明变得更加容易。

We can now return to the problem of closure of the class of regular languages ​​under regular operations, which we started in Section 1.1. Our goal is to prove that the union, concatenation, and Kleene closure of regular languages ​​are still regular. We abandoned the original attempt at this task when it turned out that dealing with the concatenation operation was too complicated. Using nondeterminism will make the proof much easier.

首先,我们再次考虑为了总数而关闭。我们之前通过构造笛卡尔积来确定性地同时模拟两台机器,从而证明了并集的封闭性。我们现在提出一个新的证明来说明基于非确定性的技术。重新审视第 45 页上显示的第一个证明可能很有价值,因为它将显示新证明是多么容易和直观。

First, let us reconsider closure under union. We proved closure under union earlier by simulating both machines simultaneously deterministically by constructing the Cartesian product. We now present a new proof to illustrate the technique based on nondeterminism. It may be valuable to review the first proof shown on page 45, to see how much easier and more intuitive the new proof is.

定理1.45

Theorem 1.45

正则语言的类由于并集操作而被封闭。

The class of regular languages ​​is closed under the union operation.

证明的概念我们有正则语言A 1A 2,我们想证明A 1 A 2是正则语言。这个想法是为语言A 1A 2采用两个 NFA N 1N 2,并将它们组合成一个新的 NFA N

Concept of the Proof We have regular languages ​​A 1 and A 2 and we want to prove that A 1 A 2 is regular. The idea is to take two NFAs, N 1 and N 2 for the languages ​​A 1 and A 2 , and combine them into one new NFA N .

如果N 1N 2接受它,机器N必须接受它的单词。新机器有一个新的初始状态,它通过ε转换分支到旧机器的初始状态。通过这种方式,新机器不确定地猜测两台机器中的哪一台应该接受输入。如果其中一台接受输入,机器N也会接受它。

Machine N must accept its word if N 1 or N 2 accepts it. The new machine has a new initial state that branches to the initial states of the old machines via ε -transitions. In this way, the new machine nondeterministically guesses which of the two machines is to accept the input it receives. If one of them accepts the input, machine N also accepts it.

1.46构建识别语言A 1 A 2

的 NFA N

Figure 1.46

Construction of NFA N recognizing language A 1 A 2

我们在下图中展示了这个结构。在左边,我们用较大的圆圈标记了机器N 1N 2的启动和接受状态,并用较小的圆圈标记了几个附加状态。右侧我们展示了如何通过包含额外的转换将N 1N 2机器组合成N。

We have shown this construction in the figure below. On the left, we have marked the start and accepting states of machines N 1 and N 2 with larger circles, and several additional states with smaller ones. On the right, we show how to combine machines N 1 and N 2 into N by adding additional transitions.

证据

Evidence

N 1 = ( Q 1 , Σ , δ 1 , q 1 , F 1 ) 识别语言A 1

Let N 1 = ( Q 1 , Σ , δ 1 , q 1 , F 1 ) recognize the language A 1 and

N 2 = ( Q 2 , Σ , δ 2 , q 2 , F 2 ) 识别语言A 2

N 2 = ( Q 2 , Σ , δ 2 , q 2 , F 2 ) recognizes the language A 2 .

我们构造N = ( Q , Σ , δ , q 0 , F ) 来识别A 1 A 2

We construct N = ( Q , Σ , δ , q 0 , F ) which is supposed to recognize A 1 A 2 .

  1. Q = { q 0 } Q 1 Q 2

    机器N的状态是所有状态N 1N 2,并补充有新的初始状态q 0

  2. Q = { q 0 } Q 1 Q 2 .

    The states of the automaton N are all the states of N 1 and N 2 , supplemented with a new initial state q 0 .

  3. 状态q 0是N的初始状态。
  4. State q 0 is the initial state of N .
  5. 接受F = F 1 F 2的状态集。

    接受N的状态是所有接受N 1N 2 的状态。因此,如果输入词被任何自动机N 1N 2接受,则N接受该输入词。

  6. The set of accepting states F = F 1 F 2 .

    The accepting states of N are all accepting states of N 1 and N 2 . Thus N accepts an input word if it is accepted by either of the automata N 1 or N 2 .

  7. 我们定义δ,以便对于任何q Q和任何a Σ ε

  8. We define δ so that for any q Q and any a Σ ε ,

我们现在可以证明由于串联而导致的闭包。回想一下,以前,如果不使用非确定性,完成证明就太困难了。

We can now prove closure under concatenation. Recall that earlier, without using nondeterminism, it turned out to be too difficult to complete the proof.

定理1.47

Theorem 1.47

正则语言的类由于串联操作而被封闭。

The class of regular languages ​​is closed under the concatenation operation.

证明的概念给定正则语言A 1A 2,我们想证明A 1   A 2也是正则语言。这个想法是为语言A 1A 2使用两个 NFA - N 1N 2 ,并将它们组合成一个新的 NFA N,类似于并集,但这次组合将以不同的方式完成,如图1.48所示。

Concept of the Proof We are given regular languages ​​A 1 and A 2 and we want to prove that A 1   A 2 is also regular. The idea is to take two NFAs – N 1 and N 2 – for the languages ​​A 1 and A 2 and combine them into a new NFA N , similarly to the union case, but this time the combination happens in a different way, as shown in Figure 1.48.

我们选择初始状态N 1作为机器N的初始状态。接受N 1 的状态接收额外的ε -转换,每当N 1处于接受状态时,这允许非皮肤分支到N 2 ,这意味着我们已经找到了从语言A 1创建单词的初始输入片段。接受N台机器的状态是接受N 2台机器的状态。通过这种方式,该机器接受输入可以分为两部分的时间,第一部分由N 1接受,第二部分由N 2接受。我们可以将N视为一台能够非机器性地猜测在哪里划分的机器。

As the initial state of machine N we choose the initial state N 1 . The accepting states of N 1 receive additional ε -transitions that allow nonderministic branches to N 2 whenever N 1 is in an accepting state, meaning that we have found the initial fragment of input that forms a word of language A 1 . The accepting states of machine N are the accepting states of machine N 2 . Thus, this machine accepts whenever the input can be split into two parts, with the first being accepted by N 1 and the second by N 2 . We can think of N as a machine that nonderministically guesses where the split should be made.

1.48识别A 1 A 2的N

的构造  

Figure 1.48

Construction of N recognizing A 1 A 2  

证据

Evidence

N 1 = ( Q 1 , Σ , δ 1 , q 1 , F 1 ) 识别语言A 1

Let N 1 = ( Q 1 , Σ , δ 1 , q 1 , F 1 ) recognize the language A 1 and

N 2 = ( Q 2 , Σ , δ 2 , q 2 , F 2 ) 识别语言A 2

N 2 = ( Q 2 , Σ , δ 2 , q 2 , F 2 ) recognizes the language A 2 .

我们构造N = ( Q , Σ , δ , q 1 , F 2 ) 来识别A 1   A 2

We construct N = ( Q , Σ , δ , q 1 , F 2 ) which is supposed to recognize A 1   A 2 .

  1. Q = Q 1 Q 2

    机器N的状态是机器N 1N 2的所有状态。

  2. Q = Q 1 Q 2 .

    The states of the automaton N are all the states of the automatons N 1 and N 2 .

  3. 状态q 1与初始状态N 1相同。
  4. The state q 1 is the same as the initial state N 1 .
  5. 接受F 2的状态与接受N 2 的状态相同。
  6. The states accepting F 2 are the same as the states accepting N 2 .
  7. 我们定义δ,以便对于每个q Q和每个a Σ ε
  8. We define δ so that for every q Q and for every a Σ ε ,

定理1.49

Theorem 1.49

正则语言的类由于星号运算符而被封闭(Kleene 闭包

The class of regular languages ​​is closed under the asterisk operator (Kleene closure ) .

证明的概念给定一个正则语言A 1,我们想证明A 1 *也是正则语言。我们将使用识别语言A 1的 NFA N 1并将其修改为识别语言A 1 *,如下图所示。生成的 NFA N将接受输入单词,只要它可以分成多个部分,使得每个部分都被N 1接受。

Concept of Proof We are given a regular language A 1 and we want to prove that A 1 * is also regular. We will use an NFA N 1 that recognizes language A 1 and modify it to recognize language A 1 * , as in the figure below. The resulting NFA N will accept an input word if it can be split into multiple parts such that each part is accepted by N 1 .

我们将构建一个N自动机作为 N 1自动机的修改,其中我们将添加从接受状态到初始状态的ε转换。这样,当处理到达N 1接受的片段的末尾时,N机器将有机会跳回初始状态并尝试读取N 1接受的另一个片段。此外,我们需要修改N以接受ε,它始终是语言A 1 *的元素。一个可能的(不是最好的)想法是简单地将初始状态添加到接受状态集中。这种方法无疑将ε添加到识别的语言中,但也可能添加其他不需要的单词。练习 1.15 给出了这个概念的缺陷的一个例子。解决这个问题的方法是添加一个新的初始状态,它也是接受状态并包含到旧初始状态的ε转换。该解决方案实现了向语言添加ε的预期效果,但没有添加任何超出它的内容。

We will construct the automaton N as a modification of the automaton N 1 , in which we add ε -transitions leading from the accepting states to the initial state. In this way, when processing reaches the end of a fragment accepted by N 1 , the automaton N will have the option of jumping back to the initial state and trying to read another fragment accepted by N 1 . In addition, we must modify N so that it accepts ε , which is always an element of the language A 1 * . One possible (not very good) idea is to simply add the initial state to the set of accepting states. This approach undoubtedly adds ε to the recognized language, but it may also add other, undesirable words. Exercise 1.15 illustrates the flaw in this idea with an example. A way to solve this problem is to add a new initial state that is also an accepting state and that contains an ε -transition to the old initial state. This solution achieves the desired effect of adding ε to the language, but without adding anything else to it.

1.50识别语言A的N

的设计*

Figure 1.50

Construction of N recognizing language A *

证明N 1 = ( Q 1 , Σ , δ 1 , q 1 , F 1 ) 识别语言A 1

Proof Let N 1 = ( Q 1 , Σ , δ 1 , q 1 , F 1 ) recognize the language A 1 .

我们构造N = ( Q , Σ , δ , q 0 , F ) 来识别语言A 1 *

We construct N = ( Q , Σ , δ , q 0 , F ) recognizing the language A 1 * .

  1. Q = { q 0 } Q 1

    N台机器的状态是N 1的状态加上一个新的初始状态。

  2. Q = { q 0 } Q 1 .

    The states of the automaton N are the states of N 1 plus the new initial state.

  3. 状态q 0是新的初始状态。
  4. State q 0 is the new initial state.
  5. F = { q 0 } F 1

    接受状态是旧的一组接受状态加上新的起始状态。

  6. F = { q 0 } F 1 .

    The accepting states are the old set of accepting states plus the new initial state.

  7. 我们定义δ,以便对于任何q Q和任何a Σ ε

  8. We define δ so that for any q Q and any a Σ ε ,

1.3

正则表达式

1.3

Regular expressions

在算术中,我们可以使用 + 和 × 运算来构建表达式,例如

In arithmetic, we can use the + and × operations to build expressions like

(5 + 3) × 4。

(5 + 3) × 4 .

类似地,我们可以使用正则运算来构建描述语言的表达式;我们称它们为正则表达式。一个例子是:

Similarly, we can use regular operations to build expressions that describe languages; we call these regular expressions . An example would be:

( 0 1 ) 0 *

( 0 1 ) 0 * .

显示的算术表达式的值为数字 32。正则表达式的值为 language。在这种情况下,该值是一种语言,由所有以01开头,后跟任意数量的零的单词组成。我们可以通过将这个表达式分成几部分来得到这个结果。首先,符号01是集合{0}{1}的缩写。因此,( 0 1 ) 意味着({ 0 } { 1 })。这部分的值为语言{ 0,1 }0 *部分表示 { 0 } *,其值是由包含任意数量的零的所有单词组成的语言。其次,就像代数中的 × 符号一样,串联符号通常隐含在正则表达式中。所以( 0∪1 ) 0 *实际上( 0∪1 ) ⚬0 *的缩写将两个部分的单词 join 连接起来以创建整个表达式的值。

The value of the arithmetic expression shown is the number 32. The value of the regular expression is the language. In this case, the value is the language of all words starting with 0 or 1 , followed by any number of zeros. We can obtain this result by splitting the expression into parts. First, the symbols 0 and 1 are shorthand for the sets { 0 } and { 1 }. Thus, ( 0 1 ) means ({ 0 } { 1 }). The value of this part is the language { 0 , 1 }. The part 0 * means { 0 } * , and its value is the language of all words containing any number of zeros. Second, like the symbol × in algebra, the concatenation symbol is often implicit in regular expressions. So ( 0 1 ) 0 * is essentially a shorthand for ( 0 1 ) 0 * . Concatenation joins the words from both parts to form the value of the entire expression.

正则表达式在计算应用中发挥着重要作用。在基于文本的应用程序中,用户可能想要搜索与某些模式匹配的字符串。正则表达式提供了描述此类模式的有效方法。 UNIX 系统上的awkgrep等实用程序、Perl 等现代编程语言以及文本编辑器都提供了使用正则表达式描述模式的机制。

Regular expressions play an important role in computer science. In text-based applications, users may wish to search for strings that match specific patterns. Regular expressions provide an efficient method for describing such patterns. Utilities such as awk and grep on UNIX systems, modern programming languages ​​such as Perl, and text editors all provide mechanisms for describing patterns using regular expressions.

1.51

Example 1.51

正则表达式的另一个例子是

Another example of a regular expression is

( 0 1 ) *

( 0 1 ) * .

我们从语言( 0∪1 )开始并使用*操作。该表达式的值是由所有可能的零和一组成的字符串组成的语言。如果Σ = { 0 , 1 },我们可以使用Σ作为正则表达式 ( 0 1 )的简写。更一般地,如果Σ是任意字母表,则正则表达式Σ描述该字母表之上的所有长度为1的单词的语言,并且Σ *描述该字母表之上的所有(任意长度)单词的语言。类似地,Σ * 1是一种包含所有以1结尾的单词的语言。语言 ( 0 Σ * ) ( Σ * 1 ) 由所有以0开头或以1结尾的单词组成。

Here we start with the language ( 0 1 ) and apply the * operation . The value of this expression is the language of all possible strings consisting of zeros and ones. If Σ = { 0 , 1 }, we can use Σ as a shorthand for the regular expression ( 0 1 ). More generally, if Σ is an arbitrary alphabet, the regular expression Σ describes the language of all words of length 1 over this alphabet, and Σ * describes the language of all words (of arbitrary length) over this alphabet. Similarly, Σ * 1 is the language of all words ending in 1 . The language ( 0 Σ * ) ( Σ * 1 ) consists of all words starting with 0 or ending with 1 .

在算术中,我们说 × 优先于 + 来指定如果有选择,我们首先执行 × 操作。因此,在表达式2+3×4中,3×4项在加法之前执行。要先进行加法,我们需要添加括号,得到表达式 (2 + 3) × 4。在正则表达式中,先进行星号运算,然后进行连接,最后进行求和,除非使用括号改变了顺序。

In arithmetic, we say that × takes precedence over + to indicate that if there is a choice, we perform the × operation first. Thus, in the expression 2 + 3 × 4 , the 3 × 4 term is performed before the addition. To perform the addition first, we add the parentheses, obtaining the expression (2 + 3) × 4 . In regular expressions, the asterisk operation is performed first, then the concatenation, and finally the sum, unless the order is changed by using parentheses.

正则表达式的正式定义

Formal definition of a regular expression

定义 1.52

Definition 1.52

如果R具有以下形式,我们就说R正则表达式

We say that R is a regular expression if R is of the form

  1. 对于字母表Σ中的某些a
  2. and for some a from the alphabet Σ ,
  3. ε ,
  4. ε ,
  5. 关于
  6. ABOUT ,
  7. ( R 1 R 2 ),其中R 1R 2是正则表达式,
  8. ( R 1 R 2 ), where R 1 and R 2 are regular expressions,
  9. ( R 1 R 2 ),其中R 1R 2是正则表达式,或
  10. ( R 1 R 2 ), where R 1 and R 2 are regular expressions, or
  11. (R 1 * ),其中R 1是正则表达式。
  12. (R 1 * ), where R 1 is a regular expression.

在第1点和第2点中,正则表达式aε分别表示语言{ a }和{ ε }。步骤3中,正则表达式Ø代表空语言。步骤4、5和6中,表达式分别表示R 1R 2表示的语言的并集或串联或R 1表示的语言Kleene闭包得到的语言。

In items 1 and 2, the regular expressions a and ε represent the languages ​​{ a } and { ε }, respectively. In item 3, the regular expression Ø represents the empty language. In items 4, 5, and 6, the expressions represent the languages ​​obtained by the union or concatenation of the languages ​​represented by R 1 and R 2 , or the Kleene closure of the language represented by R 1 , respectively .

正则表达式εØ不应混淆。表达式ε表示一种包含一个单词的语言(具体来说,是一个空单词),而Ø表示一种不包含单词的语言(空语言)。

The regular expressions ε and Ø should not be confused . The expression ε represents a language containing one word—specifically, the empty word—whereas Ø represents a language containing no words at all (an empty language).

显然,使用正则表达式本身来定义正则表达式的概念存在危险。如果是这样的话,我们定义时就会陷入恶性循环,这样的定义将是不正确的(逻辑错误)。然而,R 1R 2总是小于R。因此,我们实际上是通过更小的正则表达式来定义正则表达式,从而避免循环。这种定义称为归纳定义

Apparently, we have here the danger of defining the concept of a regular expression in terms of itself. If this were the case, we would have a vicious circle in defining , and such a definition would be incorrect (a logical fallacy). However, R 1 and R 2 are always smaller than R . Thus, in fact, we define regular expressions by smaller regular expressions, and thus avoid cyclicity. A definition of this kind is called an inductive definition .

表达式中的括号可以省略。如果是这种情况,则按照优先顺序进行处理:星号(Kleene 闭包、串联,最后并集。

Parentheses in expressions may be omitted. If so, processing is in order of precedence: asterisk (Kleene 's closure ), concatenation, and finally union.

为了方便起见,我们将使用符号R +作为RR *的缩写。换句话说,虽然R *包含R中 0 个或多个单词串联的所有单词,但语言R +包含R中1 个或多个单词串联的所有单词。所以R + ε = R *。此外,我们将R k定义为将k 个R表达式相互连接的快捷方式。

For convenience, we will use the notation R + as shorthand for RR * . In other words, if R * contains all words that are the concatenation of 0 or more words from R , then the language R + contains all words that are the concatenation of 1 or more words from R . So R + ε = R * . We further define R k as shorthand for the concatenation of k expressions of R with themselves.

当我们需要区分R正则表达式和它所描述的语言时,我们将使用符号L ( R ) 来表示R语言。

Whenever we need to distinguish between a regular expression R and the language it describes, we will use the notation L ( R ) to denote the language R .

实施例 1.53

Example 1.53

在以下几点中,我们假设字母表Σ为 { 0 , 1 }。

In the following steps we assume that the alphabet Σ is { 0 , 1 }.

  1. 0 * 10 * = { w : w包含单个1 }。
  2. 0 * 10 * = { w : w contains a single 1 }.
  3. Σ * 1 Σ * = { w : w至少包含一个1 }。
  4. Σ * 1 Σ * = { w : w contains at least one 1 }.
  5. Σ * 001 Σ * = { w : w包含子字001 }。
  6. Σ * 001 Σ * = { w : w contains substring 001 }.
  7. 1 * ( 01 + ) * = { w : w 中的每个0后面至少有一个1 }
  8. 1 * ( 01 + ) * = { w : each 0 in word w is followed by at least one 1 }.
  9. ( ΣΣ ) * ={ w : w是偶数长度的字} 5
  10. ( ΣΣ ) * = { w : w is an even-length word } 5 .
  11. ( ΣΣΣ ) * = { w : w的长度是 3 的倍数}。
  12. ( ΣΣΣ ) * = { w : length of w is a multiple of 3}.
  13. 01 10 = { 01 , 10 }。
  14. 01 10 = { 01 , 10 }.
  15. 0 Σ * 0 1 Σ * 1 0 1 = { w : w以相同符号开始和结束}。
  16. 0 Σ * 0 1 Σ * 1 0 1 = { w : w starts and ends with the same symbol}.
  17. ( 0 ε ) 1 * = 01 * 1 *

    表达式0 ε描述了语言 { 0 , ε },因此串联操作会在1 *的每个单词之前添加0ε

  18. ( 0 ε ) 1 * = 01 * 1 * .

    The expression 0 ε describes the language { 0 , ε }, so the concatenation operation adds either 0 or ε before each word of 1 * .

  19. ( 0 ε )( 1 ε ) = { ε , 0 , 1 , 01 }。
  20. ( 0 ε )( 1 ε ) = { ε , 0 , 1 , 01 }.
  21. 1 * Ø = Ø

    空集与任何集的串联总是产生空集。

  22. 1 * Ø = Ø .

    The concatenation of the empty set with any set always produces the empty set.

  23. Ø * = { ε }。

    星号(Kleene包)将某种语言中任意数量的单词聚集在一起以生成结果单词。如果语言为空,则此操作只能收集​​0 个单词,导致仅得到一个空单词。

  24. Ø * = { ε }.

    The asterisk (Kleene 's closure ) gathers together any number of words from a language to produce a result word. If the language is empty, this operation can only gather 0 words, producing only the empty word.

如果我们假设R是任意正则表达式,我们将获得以下恒等式。它们是对我们是否正确理解定义的考验。

If we assume that R is any regular expression, we obtain the following identities. They are a test of whether we understand the definition correctly.

R Ø = R

R Ø = R .

将空语言添加到任何其他语言不会改变它。

Adding an empty language to any other language will not change it.

R ε = R

R ε = R .

在任何单词后添加空格不会改变它。

Appending an empty word to any word will not change it.

然而,如果我们交换前面恒等式中的Øε,可能会导致不再满足等式。

However, if we swapped Ø and ε in the preceding identities, this would cause the equalities to no longer hold.

R ε可能不等于R。

R ε may not be equal to R .

例如,如果R = 0,则L ( R ) = {0},但L ( R ε ) = { 0 , ε }。

For example, if R = 0 , then L ( R ) = { 0 }, but L ( R ε ) = { 0 , ε }.

R Ø可能不等于R

R Ø may not be equal to R .

例如,如果R = 0,则L ( R ) = {0},但L ( R Ø ) = Ø

For example, if R = 0 , then L ( R ) = { 0 }, but L ( R Ø ) = Ø .

正则表达式是设计编程语言编译器的有用工具。编程语言的基本语法元素称为标记,例如变量名和常量,可以使用正则表达式进行描述。例如,可能包含小数部分和/或符号的数值常量可以被描述为语言元素

Regular expressions are useful tools in the design of programming language compilers. The basic syntactic elements of a programming language, called tokens , such as variable names and constants, can be described using regular expressions. For example, a numeric constant, which may contain a fractional part and/or a sign, can be described as a language element

( + ε ) ( D + D + .D * D * .D + )

(+ ε ) ( D + D + . D * D * . D + )

其中D = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } 是十进制数字的字母表。生成的单词的示例有:723.14159+7。-.01

where D = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } is the alphabet of decimal digits. Examples of generated words are: 72 , 3.14159 , +7. or -.01 .

一旦使用正则表达式通过其标记来描述编程语言的语法,自动化系统就可以生成词法分析器,这是编译器中执行输入程序预处理的部分。

Once the syntax of a programming language is described using regular expressions through its tokens, automated systems can generate a lexical analyzer, a part of the compiler that performs preprocessing of the input program.

与有限自动机的等价

Equivalence with finite automata

正则表达式和有限自动机在表达能力方面是等效的。这个事实令人惊讶,因为有限自动机似乎是完备不同的东西。但是,任何正则表达式都可以转换为可识别表达式所描述的语言的有限自动机,反之亦然。回想一下,正则语言是被某种有限自动机识别的语言。

Regular expressions and finite automata are equivalent in terms of their expressive power. This is surprising, since finite automata seem to be quite different. However, any regular expression can be converted into a finite automaton that recognizes the language described by the expression, and vice versa. Recall that a regular language is one that is recognized by a finite automaton.

定理1.54

Theorem 1.54

当且仅当一种语言由某种正则表达式描述时,它才是正则语言。

A language is regular if and only if it is described by some regular expression.

该定理有两个方向。我们将制定并证明每个方向作为一个单独的引理。

The theorem has two directions. We will formulate and prove each direction as a separate Lemma.

引理 1.55

Lemma 1.55

如果一种语言是用正则表达式描述的,那么它就是正则语言。

If a language is described by a regular expression, it is a regular language.

证明的概念 让我们假设我们有一个描述某种语言A 的正则表达式R我们将向您展示如何将它们转换为可识别A 的NFA。根据推论 1.40,如果 NFA 识别语言A,则语言A是正则语言。

Concept of Proof Suppose we have a regular expression R describing some language A . We show how to convert it into an NFA that recognizes A . By Corollary 1.40, if the NFA recognizes A , then A is regular.

证明我们将把R转换为 NFA N。我们将考虑正则表达式的正式定义中出现的六种情况。

Proof We convert R to an NFA N . We consider six cases appearing in the formal definition of regular expressions.

  1. R = a对于某些a Σ。那么L ( R ) = { a } 并且以下 NFA 识别L ( R )。

    请注意,该机器符合 NFA 定义,但不符合 DFA 定义,因为它包含一些状态,对于每个可能的输入符号都没有传出转换。当然,我们可以在这里提出一个等价的 DFA,但 NFA 对我们来说就足够了,而且更容易描述。

    形式上,N = ({ q 1 , q 2 }, Σ , δ , q 1 , { q 2 }),其中我们可以通过表述δ ( q 1 , a ) = { q 2 } 和δ ( r , b ) = Ø对于r q 1b a

  2. R = a for some a Σ . Then L ( R ) = { a }, and the following NFA recognizes L ( R ).

    Note that this machine fits the definition of an NFA but not the definition of a DFA, since it contains some states with no outgoing transitions for each possible input symbol. Of course, we could represent an equivalent DFA here, but an NFA suffices for us and is easier to describe.

    Formally, N = ({ q 1 , q 2 }, Σ , δ , q 1 , { q 2 }), where δ can be described by stating that δ ( q 1 , a ) = { q 2 } and δ ( r , b ) = Ø for r q 1 or b a .

  3. R = ε。那么L ( R ) = { ε } 并且以下 NFA 识别L ( R )。

    形式上,N = ({ q 1 }, Σ , δ , q 1 , { q 1 }),其中对于任何rb , δ ( r , b ) = Ø

  4. R = ε . Then L ( R ) = { ε } and the following NFA recognizes L ( R ).

    Formally, N = ({ q 1 }, Σ , δ , q 1 , { q 1 }), where δ ( r , b ) = Ø for any r and b .

  5. R = Ø。那么L ( R ) = Ø并且以下 NFA 识别L ( R )。

    形式上,N = ({ q }, Σ , δ , q , Ø ),其中对于任何rb , δ ( r , b ) = Ø

  6. R = Ø . Then L ( R ) = Ø and the following NFA recognizes L ( R ).

    Formally, N = ({ q }, Σ , δ , q , Ø ), where δ ( r , b ) = Ø for any r and b .

  7. R = R 1 R 2
  8. R = R 1 R 2 .
  9. R = R 1 R 2
  10. R = R 1 R 2 .
  11. R = R * 1
  12. R = R * 1

对于最后三种情况,我们将使用证明中给出的构造,即正则语言的类对于正则操作是封闭的。换句话说,我们将使用来自正则语言类封闭性证明的适当构造,从R 1R 2(或在 6 的情况下仅R 1 )的 NFA 构造R的 NFA这个操作。

For the last three cases we will use the constructions given in the proofs that the class of regular languages ​​is closed under regular operations. In other words, we will construct an NFA for R from the NFA for R 1 and R 2 (or just R 1 in case 6) using the appropriate construction from the proof of the closure of the class of regular languages ​​for this operation.

这就完成了定理 1.54 证明的第一部分,确保条件的更简单方向为真当且仅当。在继续第二个方向之前,让我们考虑几个使用上述过程将正则表达式转换为 NFA 的示例。

This completes the first part of the proof of Theorem 1.54, ensuring that the simpler direction of the condition is true if and only if. Before moving to the second direction, let us consider a few examples in which we use the above procedure to transform a regular expression into an NFA.

1.56

Example 1.56

我们将通过一系列步骤将正则表达式 ( ab a ) *转换为 NFA。我们将使用自上而下的方法,从最小的子表达式开始,一直到更大的子表达式,直到获得原始表达式的 NFA,如下图所示。请注意,此过程通常不会生成状态最少的 NFA。在此示例中,该过程创建具有八个状态的 NFA,但最小的等效 NFA 仅具有两个状态。你能找到吗?

We will convert a regular expression ( ab a ) * to an NFA in a sequence of steps. We will use a bottom-up approach, starting with the smallest subexpressions and working our way up until we obtain an NFA for the original expression, as shown in the diagram below. Note that this procedure does not generally produce an NFA with the smallest number of states. In this example, the procedure produces an NFA with eight states, but the smallest equivalent NFA has only two states. Can you find it?

1.57

从正则表达式构建 NFA ( ab a ) *

Figure 1.57

Building an NFA from a regular expression ( ab a ) *

1.58

Example 1.58

图 1.59 显示了正则表达式 ( a b ) * aba到 NFA 的转换。这里不介绍一些小步骤。

Figure 1.59 shows the conversion of a regular expression ( a b ) * aba to NFA. Several minor steps are not shown here.

1.59从正则表达式 ( a b ) * aba

构建 NFA

Figure 1.59

Building an NFA from a regular expression ( a b ) * aba

现在让我们从另一个方向来证明定理1.54。

Let us now turn to the proof of Theorem 1.54 in the other direction.

引理 1.60

Lemma 1.60

如果一种语言是正则语言,则它可以表示为正则表达式。它是通过正则表达式来描述的。

If a language is regular, then it can be represented as a regular expression. It is described by a regular expression.

证明的概念我们要证明如果语言A是正则的,那么它可以表示为正则表达式。由于A是正则的,因此它被一些 DFA 接受。我们将描述将确定性有限自动机转换为等效正则表达式的过程。

Proof Concept We are to show that if a language A is regular, then it can be represented as a regular expression. Since A is regular, then it is accepted by some DFA. We describe a procedure for converting deterministic finite automata to equivalent regular expressions.

我们将这个过程分为两部分,使用一种称为广义非确定性有限自动机(GNFA)的新型有限自动机。我们将首先向您展示如何将 DFA 转换为等效的 GNFA,然后如何将 GNFA 转换为正则表达式。

We will split this procedure into two parts, using a new type of finite automaton called a generalized nondeterministic finite automaton ( GNFA). First, we will show how to transform DFAs into equivalent GNFAs, and then how to transform GNFAs into regular expressions.

广义非确定性有限自动机只是非确定性有限自动机,其中转移可以使用任何正则表达式作为标签,而不仅仅是字母表或ε的元素。 GNFA 从输入中读取符号块,不一定像正则 NFA 那样只是单个符号。 GNFA 通过从输入中读取符号块,沿着转换箭头从一种状态移动到另一种状态,该符号块本身形成由该转换的正则表达式描述的单词。 GNFA 是不确定的,因此可以包含处理同一输入单词的许多不同方式。如果通过以这种方式操作,GNFA 可以在到达接受状态时读取整个输入字,则它接受其输入。下图显示了 GNFA 的示例。

Generalized nondeterministic finite automata are simply nondeterministic finite automata in which the transitions can have arbitrary regular expressions as labels, instead of just elements of the alphabet or ε . A GNFA reads blocks of symbols from its input, not necessarily just single symbols like an ordinary NFA. A GNFA transitions from one state to another along a transition arrow by reading a block of symbols from the input, which itself forms a word described by the regular expression for that transition. A GNFA is nondeterministic, and thus can contain many different ways of processing the same input word. A GNFA accepts its input if, acting in this way, it can read the entire input word while still arriving at an accepting state. The figure below shows an example of a GNFA.

1.61

广义非确定性有限状态机

Figure 1.61

Generalized nondeterministic finite automaton

为了方便起见,我们将要求 GNFA 始终具有满足以下条件的特殊形式。

For convenience, we will require that a GNFA always have a special form that meets the conditions below.

  • 初始状态可以转换到所有其他状态,但没有来自任何其他状态的转换。
  • The initial state has transitions to all other states, but no transitions coming from any other state.
  • 只能有一个接受状态,并且必须有从所有其他状态到该状态的转换,但不能有到任何其他状态的传出转换。而且,接受状态不能与初始状态相同。
  • There can be only one accepting state, and there must be transitions to it from every other state, but no outgoing transitions to any of the other states. Furthermore, the accepting state cannot be identical to the initial state.
  • 除了初始状态和接受状态之外,必须存在从每个状态到每个状态的转换,包括到相同状态的转换。
  • Except for the start and accepting states, there must be transitions from every state to every state, including those to the same state.

您可以轻松地将任何 DFA 转换为特殊形式的 GNFA。我们只需将具有ε转换的新初始状态添加到旧初始状态,并从所有旧接受状态添加具有ε转换的新接受状态。如果任何转换具有多个标签(或者如果同一方向上的两个状态之间存在多个转换),我们将每个转换替换为一个标签为先前标签之和的单个转换。最后,我们在那些未连接的状态之间添加带有标签Ø的转换。最后一步不会更改机器识别的语言,因为带有标签Ø的转换将永远无法使用。从现在开始,我们将假设所有考虑的 GNFA 都具有特殊形式。

It is easy to transform any DFA into a special-form GNFA. We simply add a new initial state with an ε -transition to the old initial state, and a new accepting state with ε -transitions from all the old accepting states. If any transition has multiple labels (or if there are multiple transitions between two states in the same direction), we replace each with a single transition whose label is the sum of the previous labels. Finally, we add transitions labeled Ø between those states that were not connected. This last step does not change the language recognized by the automaton, since a transition labeled Ø can never be used. From now on, we will assume that all GNFAs under consideration have a special form.

现在我们可以向您展示如何将 GNFA 转换为正则表达式。假设 GNFA 包含k 个状态。然后,由于 GNFA 必须包含初始状态和接受状态,并且它们必须彼此不同,因此我们知道k ≥ 2。如果k > 2,我们将构造一个具有k − 1 个状态的等效 GNFA 。可以在新的 GNFA 上重复此步骤,直到它减少到两个状态。如果k = 2,则 GNFA 包含从初始状态到接受状态的一次转换。此转换的标签是与原始 GNFA 等效的正则表达式。将三态 DFA 转换为等效正则表达式的步骤如下图所示。

Now we can show how to convert a GNFA to a regular expression. Suppose that the GNFA contains k states. Then, since the GNFA must contain initial and accepting states and they must be different, we know that k ≥ 2. If k > 2, then we construct an equivalent GNFA with k − 1 states. This step can be repeated for the new GNFA until it is reduced to two states. If k = 2, then the GNFA contains one transition from the initial state to the accepting state. The label of this transition is a regular expression equivalent to the original GNFA. The steps for converting a three-state DFA to an equivalent regular expression are shown in the figure below.

1.62

DFA转换为正则表达式的常见状态

Figure 1.62

Typical states of converting a DFA to a regular expression

关键步骤是当k > 2时构造一个少一个状态的等效 GNFA 。我们通过选择某个状态,将其从机器中删除,然后修复其余状态以便仍然识别相同的语言来实现这一点。任何状态都适合于此,只要它不是初始状态或接受状态。我们确信这样的状态存在,因为k > 2。我们将被删除的状态称为q rip

The key step is to construct an equivalent GNFA with one less state when k > 2. We achieve this by choosing some state, removing it from the machine, and repairing the remainder so that the same language is still recognized. Any state will do, as long as it is neither the initial nor the accepting state. We are sure that such a state exists, since k > 2. Let us call the removed state q rip .

删除q rip后,我们通过更改每个剩余箭头的标签中的正则表达式来修复自动机。新标签通过添加回丢失的计算来补偿q rip的缺失。从状态q i到状态q j 的新标签是一个正则表达式,描述可以直接或通过q rip将机器从状态q i带到q j的所有单词。这种方法如图 1.63 所示。

After removing q rip , we repair the machine by changing the regular expressions in the labels of each of the remaining arrows. The new labels compensate for the absence of q rip by adding back the lost computations. The new label leading from state q i to state q j is a regular expression describing all the words that could take the machine from state q i to q j either directly or via q rip . This approach is illustrated in Figure 1.63.

1.63

构建一个少一个状态的等效 GNFA

Figure 1.63

Constructing an equivalent GNFA with one less state

如果在较早的机器上

If in the previous machine

  1. q导致q撕裂带有标签R 1的转换,
  2. q and leads to q rip via the transition labeled R 1 ,
  3. q rip通过带有标签R 2的转换通向自身,
  4. q rip leads to itself via a transition labeled R 2 ,
  5. q rip通过带有标签R 3的转换通向q j
  6. q rip leads to q j via a transition labeled R 3 ,
  7. q i通过带有标签R 4的转换通向q j
  8. q i leads to q j via a transition labeled R 4 ,

那么在新机器中,从q i q j 的过渡将被赋予一个标签

then in the new machine the transition from q i to q j will be labeled

( R 1 )( R 2 ) * ( R 3 ) ( R 4 )。

( R 1 )( R 2 ) * ( R 3 ) ( R 4 ).

我们对从任何状态q i到任何状态的每个转换进行这样的更改,包括q i = q j的情况。新机器可以识别原始语言。

We make this change for each transition from any state q i to any state, including the case where q i = q j . The new machine recognizes the original language.

证明 我们现在将形式化所提出的证明想法。首先,为了便于证明,我们正式定义了上面所示的新型自动机。 GNFA 接近非确定性有限状态机,但转换函数除外,其形式为

Proof We now formalize the presented idea of ​​proof. First, to facilitate the proof, we formally define the new type of automaton shown above. GNFA is similar to a nondeterministic finite automaton, except for the transition function, which has the form

δ : ( Q − { q接受}) × ( Q − { q开始}) → R

δ : ( Q − { q accept }) × ( Q − { q start }) → R .

符号R表示字母表Σ上所有正则表达式的集合,q startq Accept分别是初始状态和接受状态。如果δ ( q i , q j ) = R ,这意味着从状态q i到状态q j的转换以正则表达式R作为其标签。转换函数的域是 ( Q − { q Accept }) × ( Q − { q start }),因为根据特殊形式,转换将每个状态连接到每个其他状态,除了没有离开或进入q 的转换之外接受q开始

The symbol R denotes the set of all regular expressions over the alphabet Σ , and q start and q accept are the initial and accepting states, respectively. If δ ( q i , q j ) = R , this means that the transition from state q i to state q j has as its label the regular expression R . The domain of the transition function is ( Q − { q accept }) × ( Q − { q start }), since, according to the special form, transitions connect every state to every other state, with the exception that there are no transitions leaving q accept or entering q start .

定义 1.64

Definition 1.64

广义非确定性有限自动机(GNFA ) 是一个有序五元组 (5 元组) ( Q , Σ , δ , q start , q Accept ),其中

A generalized nondeterministic finite automaton (GNFA) is an ordered five-tuple ( Q , Σ , δ , q start , q accept ), where

  1. Q是有限状态集,
  2. Q is a finite set of states,
  3. Σ是输入字母表,
  4. Σ is the input alphabet,
  5. δ : ( Q − { q Accept }) × ( Q − { q start }) R是传递函数,
  6. δ : ( Q − { q accept }) × ( Q − { q start }) R is the transition function,
  7. q start是初始状态,
  8. q start is the initial state,
  9. q Accept是接受状态。
  10. q accept is the accepting state.

如果w = w 1 w 2 …w k ,则 GNFA 接受属于Σ *的词w,其中每个w i属于Σ *,并且存在状态序列q 0 , q 1 , …, q k,使得

GNFA accepts a word w belonging to Σ * , if w = w 1 w 2 …w k , where each w i belongs to Σ * , and there is a sequence of states q 0 , q 1 , …, q k , such that

  1. q 0 = q start是初始状态,
  2. q 0 = q start is the initial state,
  3. q k = q accept是接受状态,
  4. q k = q accept is the accepting state,
  5. 对于每个i存在w i L ( R i ),其中R i = δ ( q i −1 , q i );换句话说,R i是描述从q i -1q i 的转变的表达式。
  6. for every i there exists w i L ( R i ), where R i = δ ( q i −1 , q i ); in other words, R i is an expression describing the transition from q i −1 to q i .

回到引理 1.60 的证明,令M为语言A的 DFA 。然后,我们可以通过添加新的起始状态和新的接受状态以及必要时的其他转换,将M转换为 GNFA G。我们将使用 CONVERT (G)过程,它接受 GNFA 并返回等效的正则表达式。此过程使用递归,这意味着它会调用自身。我们避免陷入无限循环,因为该过程仅调用自身来处理 GNFA,而 GNFA 的状态少了一个。 GNFA 只有两个状态的情况无需递归处理。

Returning to the proof of Lemma 1.60, let M be a DFA for language A . We can then convert M to a GNFA G by adding a new start state and a new accepting state, and additional transitions as needed. We use the procedure CONVERT (G) , which takes a GNFA and returns an equivalent regular expression. This procedure uses recursion , which means that it calls itself. We avoid getting into an infinite loop because the procedure only calls itself to process a GNFA that has one fewer state. The case where a GNFA has only two states is handled without recursion.

转换(G):

CONVERT( G ):

  1. k为机器G的状态数。
  2. Let k be the number of states of the automaton G .
  3. 如果k = 2,则G必须由初始状态、接受状态以及将它们与包含正则表达式R的标签连接起来的单个转换组成。我们返回表达式R
  4. If k = 2, then G must consist of an initial state, an accepting state, and a single transition connecting them with a label containing the regular expression R . We return the expression R .
  5. k > 2 时,我们选择与q startq Accept不同的任何状态q rip Q,并令G'为 GNFA ( Q' , Σ , δ' , q start , q Accept ),其中

    Q' = Q − { q撕裂},

    对于任意q i Q 0 − { q Accept } 和任意q j Q' − { q start },令

    δ' ( q i , q j ) = ( R 1 )( R 2 ) * ( R 3 ) ( R 4 )

    其中,R 1 = δ ( q i , q rip ),R 2 = δ ( q rip , q rip ),R 3 = δ ( q rip , q j ) 且R 4 = δ ( q i , q j )。

  6. When k > 2, we choose an arbitrary state q rip Q different from q start and q accept and let G' be GNFA ( Q' , Σ , δ' , q start , q accept ), where

    Q' = Q − { q rip },

    and for any q i Q 0 − { q accept } and any q j Q' − { q start }, let

    δ' ( q i , q j ) = ( R 1 )( R 2 ) * ( R 3 ) ( R 4 )

    where R 1 = δ ( q i , q rip ), R 2 = δ ( q rip , q rip ), R 3 = δ ( q rip , q j ) and R 4 = δ ( q i , q j ).

  7. 我们计算 CONVERT( G' ) 并返回该值。

    我们现在将证明 CONVERT 返回正确的值。

  8. We calculate CONVERT( G' ) and return that value.

    We will now demonstrate that CONVERT returns the correct value.

声明 1.65

Statement 1.65

对于任何 GNFA G,正则表达式CONVERT( G ) 等价于G。

For any GNFA G , the regular expression CONVERT( G ) is equivalent to G .

我们通过对GNFA 状态数k进行归纳来证明这一论点。

We will prove this theorem by induction on k , the number of GNFA states.

基本步骤:我们在k = 2 个状态下证明论文的正确性。如果G只有两个状态,那么它只能包含从初始状态到接受状态的单个转换。这个转换的标签中的正则表达式描述了所有允许G机到达接受状态的单词。因此,这个表达式等价于G。

Basic Step : We prove the theorem for k = 2 states. If G has only two states, then it can contain only a single transition from the initial state to an accepting state. The regular expression in the label of this transition describes all the words that allow G to reach an accepting state. This expression is therefore equivalent to G .

归纳步骤:我们假设该命题对于k − 1 成立,并且我们使用这个假设来证明它对于k状态也成立。首先,我们证明GG'识别相同的语言。假设G接受中的输入单词。然后,在计算的接受分支中, G一一遍历状态:

Inductive Step : We assume that the thesis is true for k − 1, and we use this assumption to show that it is also true for k states. We first show that G and G' recognize the same language. Suppose G accepts an input word w . Then, in the accepting branch of the computation, G goes through the states in turn:

q开始q 1q 2q 3,...,q接受

q start , q 1 , q 2 , q 3 , …, q accept .

如果这些状态都不是q rip的删除状态,那么显然G'也接受w。这是因为描述G'中转换的每个新正则表达式都包含旧正则表达式作为总和的一部分。

If none of these states is a deleted state of q rip , then it is obvious that G' also accepts w . This is because each of the new regular expressions describing transitions in G' includes the old regular expressions as part of the union.

如果q rip出现在上述序列中,则删除所有出现的它会产生一串状态,描述G' 的接受计算。状态q iq j发生在q rip(状态的子序列)发生之前和之后,对应于连接这些状态的转换上的新正则表达式,它描述了从q iq j 的所有单词通过机器G中的q rip。因此G'接受w

If q rip appears in the above sequence, then removing all occurrences of it gives a sequence of states that describes an accepting computation of G' . The states q i and q j appearing just before and just after the occurrence of (a subsequence of states of) q rip correspond to a new regular expression on the transition connecting these states that describes all the words leading from q i to q j via q rip in the automaton G . Thus G' accepts w .

现在考虑相反的方向并假设G'接受中的输入单词。由于G'中任何两个状态q iq j之间的任何转换都直接或通过q rip描述了G中携带q iq j 的一组字,因此G也必须接受w。因此,GG'是等价的。

Now consider the opposite direction and assume that G' accepts an input word w . Since any transition between any two states q i and q j in G' describes the set of words that take q i to q j in G either directly or via q rip , G must also accept w . Hence G and G' are equivalent.

归纳假设指出,当算法针对输入G'递归调用自身时,结果是等价于G'的正则表达式,因为G'包含k − 1 个状态。因此这个正则表达式也等价于G,所以我们证明了算法的正确性。

The inductive conjecture states that when an algorithm calls itself recursively for an input G' , the output is a regular expression that is equivalent to G' , since G' contains k − 1 states. Hence this regular expression is also equivalent to G , and so we have proven the correctness of the algorithm.

这就完成了定理 1.65、引理 1.60 以及定理 1.54 的证明。

This completes the proof of Theorem 1.65, Lemma 1.60, and consequently Theorem 1.54.

实施例 1.66

Example 1.66

在此示例中,我们将使用前面所示的算法将 DFA 转换为正则表达式。我们将从图 1.67(a) 所示的二态 DFA 开始。

In this example, we will use the algorithm shown earlier to transform a DFA into a regular expression. We will start with the two-state DFA shown in Figure 1.67(a).

在图1.67(b)中,我们通过添加一个新的开始状态和一个新的接受状态来创建一个四状态GNFA,分别命名为sa,而不是q startq accept,这样我们就可以方便地将它们放在数字。为了避免混淆,我们没有用Ø labels 绘制箭头,尽管它们存在。请注意,我们已从输出 DFA 中删除了到状态 2 的环回箭头上的标签ab,并且标签a b位于相应的 GNFA 点处。我们这样做是因为 DFA 中的标签代表两种转换,一种用于a,一种用于b,而 GNFA 只能有一种从状态 2 到其自身的转换。

In Figure 1.67(b) we create a four-state GNFA by adding a new start state and a new accepting state, named s and a respectively, instead of q start and q accept , so that we can conveniently place them in the figure. To avoid clutter, we have not drawn the arrows labeled Ø , although they are present. Note that we have removed the label a , b on the loopback arrow to state 2 from the output DFA with the label a b at the corresponding point in the GNFA. We did this because a label in a DFA represents two transitions, one for a and one for b , whereas a GNFA can have only one transition from state 2 to itself.

在图 1.67(c) 中,我们删除了状态 2 并更新了剩余箭头的标签。在这种情况下,唯一会改变的标签是从状态 1 到a 的标签。在 (b) 部分中它是Ø,但在 (c) 部分中它是b ( a b ) *。我们通过执行 CONVERT 过程的步骤 3 获得此结果。状态q i是状态 1,状态q jaq rip是状态 2,因此R 1 = bR 2 = a bR 3 = εR 4 = Ø。因此,从状态 1 到a 的箭头的新标签是 (b)( a b ) * ( ε ) Ø。该正则表达式可以简化为b ( a b ) *

In Figure 1.67(c), we have removed state 2 and updated the labels of the remaining arrows. In this case, the only label that changes is the one from state 1 to a . In part (b), this was Ø , but in part (c) it is b ( a b ) * . We obtained this result by executing step 3 of the CONVERT procedure. State q i is state 1, state q j is a , and q rip is state 2, so R 1 = b , R 2 = a b , R 3 = ε , and R 4 = Ø . Thus, the new label of the arrow from state 1 to a is (b)( a b ) * ( ε ) Ø . This regular expression can be simplified to b ( a b ) * .

在图 1.67(d) 中,我们从 (c) 部分中删除了状态 1 并执行了类似的过程。由于只剩下初始状态和接受状态,因此连接它们的箭头标签是与原始DFA等效的正则表达式。

In Figure 1.67(d), we have removed state 1 from part (c) and performed an analogous procedure. Since only the initial state and the accepting state remain, the label of the arrow connecting them is a regular expression equivalent to the original DFA.

1.67

将二态 DFA 转换为等效的正则表达式

Figure 1.67

Converting a two-state DFA to an equivalent regular expression

1.68

Example 1.68

在此示例中,我们从三态 DFA 开始。后续转换步骤如下图所示。

In this example, we start with a three-state DFA. The conversion steps are shown in the following illustration.

1.69

将三态 DFA 转换为等效的正则表达式

Figure 1.69

Converting a three-state DFA to an equivalent regular expression

1.4

非正则语言

1.4

Irregular languages

要了解有限状态机的强大功能,您还需要了解它们的局限性。在本节中我们将展示如何证明某些语言无法被任何有限自动机识别。

To understand the power of finite automata, one must also understand their limitations. In this section, we will show how to prove that certain languages ​​cannot be recognized by any finite automaton.

让我们假设语言B = { 0 n 1 n : n ≥ 0}。如果我们尝试找到一个能够识别语言B的 DFA ,我们会发现机器在读取输入时似乎必须记住到目前为止它已经看到了多少个零。由于这些零的数量没有限制,因此机器必须跟踪无限数量的可能性。然而,这对于任何有限数量的状态都是不可行的。

Assume the language B = { 0 n 1 n : n ≥ 0}. If we try to find a DFA that recognizes the language B , we find that the machine, it seems, needs to remember how many zeros it has seen so far while reading the input. Since the number of these zeros is not bounded, the machine will have to keep track of an infinite number of possibilities. However, this is not feasible with any finite number of states.

然后我们提出一种方法来证明像B这样的语言不是正则语言。由于零的数量是无限的,所提出的论点是否已经证明了非正则性?他不领导。仅仅因为一种语言看起来需要无限的内存并不一定意味着它实际上需要无限的内存。这对于语言B来说实际上是正确的;然而,还有其他语言看似也需要无限数量的可能性,尽管实际上它们是正则的。例如,考虑字母表上的两种语言Σ = { 0 , 1 }:

Next, we will present a method for proving that languages ​​like B are not regular. Doesn't the argument already prove irregularity, since the number of zeros is unlimited? It doesn't. Just because a language seems to require unlimited memory doesn't mean that it does. This is indeed true for B ; but there are other languages ​​that also seem to require an unlimited number of possibilities, but are in fact regular. For example, consider two languages ​​over the alphabet Σ = { 0 , 1 }:

C = { w : w包含相同数量的 0 和 1},

C = { w : w contains an equal number of zeros and ones},

D = { w : w包含相同次数的 0110作为子词}。

D = { w : w contains an equal number of occurrences of 01 and 10 as substrings}.

乍一看,人们可能会认为识别机器必须计算每个实例中的出现次数,因此这些语言中没有一种看起来是规则的。正如预期的那样,C不是正则的,但令人惊讶的是,D是正则的!6因此,直觉有时会让我们误入歧途,这就是为什么我们需要数学证据来确定。在本节中我们将向您展示如何证明某些特定语言是非正则的。

At first glance, one might think that the recognition machine must count the occurrences in each case, and thus none of these languages ​​seem regular. As expected, C is not regular, but surprisingly, D is regular! 6 So intuition can sometimes lead us astray, and that is why we need mathematical proofs to be sure. In this section, we show how to prove that certain specific languages ​​are not regular.

正则语言的泵送引理

The pumping lemma for regular languages

我们证明非正则性的技术源自正则语言定理,传统上称为引理。该定理指出所有正则语言都具有一些特殊属性。如果我们能够证明某种语言不具有这种性质,我们就可以确定它不是正则的。该属性表明,语言中的任何单词都可以“膨胀”,只要它至少与某个特定值(称为泵长度)一样长。我们的意思是,这样的单词包含可以重复任意多次的部分(子词),并且生成的单词仍然属于该语言。

Our technique for proving irregularity comes from a theorem about regular languages, traditionally called the pumping lemma . This theorem states that all regular languages ​​have a certain special property. If we can show that a language does not have this property, we are certain that it is not regular. This property states that any word of the language can be "pumped up" if it is at least as long as some special value, called the pumping length . By this we mean that such a word contains a part (a subword) that can be replicated any number of times, and the resulting word will still belong to the language.

定理1.70

Theorem 1.70

泵 引理 如果A是正则语言,则存在一个数字p(泵长度),使得如果s是A中长度至少为p的任何单词,则s可以分为三部分, s = xyz,满足符合以下条件: :

Pumping  Lemma  If A is a regular language, then there is a number p (the pumping length) such that if s is any word in A of length at least p , then s can be split into three parts, s = xyz , satisfying the following conditions:

  1. 对于所有i ≥ 0,xyiz A
  2. for all i ≥ 0, xy i z A ,
  3. | y | > 0,
  4. | y | > 0,
  5. | XY | ≤ p
  6. | xy | ≤ p .

让我们回想一下条目 | s |是单词s的长度,y i是单词y的i 个副本的串联,并且y 0等于ε

Recall that the notation | s | denotes the length of word s , y i is the concatenation of i copies of word y , and y 0 is equal to ε .

s被划分为xyz部分时,xz可以是空字( ε ),但条件 2 表明y ε。可以看出,如果没有条件 2,该陈述就很简单为真。条件 3 规定xy部分的长度最多为p。这是一个附加的技术条件,有时在证明某些语言非正则时很有用。对于条件3的应用,参见例1.74。

When s is partitioned into parts xyz , either x or z can be empty words ( ε ) , but condition 2 states that y ε . It can be seen that without condition 2 the theorem would be trivially true. Condition 3 states that the parts x and y together have length at most p . This is an additional technical condition that is sometimes useful in proving that certain languages ​​are not regular. An application of condition 3 is given by Example 1.74.

证明的概念M =( Q , Σ , δ , q 1 , F ) 是一个识别A 的DFA 。我们将泵浦长度p指定为等于状态数M的值。我们将证明语言A中长度至少为p的任何单词都可以分为满足我们的三个条件的三个部分xyz。但是如果A中没有一个单词的长度至少为p呢?那么我们的任务就更容易了,因为定理变得微不足道:显然,如果不存在这样的单词,则长度至少为p的所有单词都满足所有三个条件。

Concept of the Proof Let M = ( Q , Σ , δ , q 1 , F ) be a DFA recognizing A . We assign the pumping length p to a value equal to the number of states in M ​​. We show that any word of length at least p in A can be partitioned into three parts xyz satisfying our three conditions. But what if no word in A has length at least p ? Then our task is even easier, since the theorem becomes trivially true: of course, all three conditions are satisfied for all words of length at least p , if no such words exist.

如果属于A的s的长度至少为p ,请考虑机器M在处理输入s时经过的状态序列。它从初始状态q 1开始,然后进入状态q 3,然后进入q 20,然后进入q 9等等,直到到达状态q 13中的单词s的末尾。由于s属于A,我们知道M接受s,因此q 13是接受状态。

If s of A is of length at least p , consider the sequence of states that machine M goes through while processing input s . It starts with the initial state q 1 , then goes to, for example, state q 3 , then to q 20 , then to q 9 , and so on, until it reaches the end of word s in state q 13 . Since s is of A , we know that M accepts s , so q 13 is an accepting state.

如果我们假设n是s的长度,则状态序列q 1 , q 3 , q 20 , q 9 , …, q 13 的长度为n + 1。由于n不小于p,所以我们知道n + 1 大于p ,即状态数M。因此,字符串必须包含重复状态。这个结果是鸽巢规则的一个例子,这是一个有点奇特的名称,用于描述一个相当明显的事实:如果我们尝试将p 个项目排列到少于p 个盒子中,则某个盒子必须包含多个项目。

If we take n to be the length of s , then the sequence of states q 1 , q 3 , q 20 , q 9 , …, q 13 has length n + 1. Since n is not less than p , we know that n + 1 is greater than p , the number of states of M . Thus, the sequence must contain a repeated state. This result is an example of the pigeonhole principle , a slightly fancy name for the rather obvious fact that if we try to arrange p items into fewer than p pigeonholes, some pigeonhole must contain more than one item.

下图显示了单词s以及M在处理s时经历的状态序列。在此示例中,状态q 9是重复的状态。

The following figure shows a word s and the sequence of states that M goes through while processing s . In this example, state q 9 is the one that repeats.

1.71 M读取单词s

的重复状态示例

Figure 1.71

Example showing the repeating state when reading word s by M

我们现在可以将s分为三部分xyzx部分是s中出现在q 9之前的部分,y部分是两次出现q 9之间的部分,z部分是s中第二次出现q 9之后的剩余部分。因此,xM从状态q 1带到q 9y将 M 从q 9带到q 9zMq 9带到接受状态q 13,如下图所示。

We can now divide s into three parts x , y , and z . The x part is the part of s that occurred before q 9 , the y part is the part between the two occurrences of q 9 , and the z part is the remaining part of s that occurs after the second occurrence of q 9 . Thus x takes M from state q 1 to q 9 , y takes M from q 9 back to q 9 , and z takes M from q 9 to the accepting state q 13 , as in the figure below.

1.72

显示单词xyz如何影响M的示例

Figure 1.72

An example showing how the words x , y , and z affect M

让我们看看为什么s 的这种除法满足给定的条件。假设我们运行机器M来输入xyyz。我们知道xM从状态q 1带到q 9,然后第一个yMq 9带回到q 9 ,第二个y也是如此,然后z将机器带到状态q 13。由于q 13是接受状态,因此M接受输入xyyz。类似地,对于任何i > 0,它也会接受xyz 。在i = 0的情况下,xyz = xz,出于类似的原因可以接受。这确保满足条件 1。

Let's see why such a partition s satisfies the given conditions. Suppose we run the machine M for input xyyz . We know that x takes M from state q 1 to q 9 , and then the first y takes M from q 9 back to q 9 , which does the second y , and then z moves the machine to state q 13 . Since q 13 is an accepting state, M accepts input xyyz . Similarly, it will also accept xy and z for any i > 0. For i = 0, xy and z = xz , which is accepted for analogous reasons. This satisfies condition 1.

通过检查条件 2,我们可以看到 | y | > 0,因为它是s的一部分,发生在状态q 9的两次不同出现之间。

Checking condition 2, we can see that | y | > 0, as it is the part of s that occurred between two different occurrences of state q 9 .

为了获得条件3,我们需要确保q 9是单词第一个重复的条件。根据鸽笼规则,序列中的前p +1 个状态必须包含重复。因此| XY | ≤ p

To obtain condition 3, we need to make sure that q 9 is the first repeating state in the word. By the pigeonhole principle, the first p + 1 states in the sequence must contain a repeat. Hence, | xy | ≤ p .

证明 M = ( Q , Σ , δ , q 1 , F ) 为识别语言A 的DFA,设p为M 的状态数。

Proof Let M = ( Q , Σ , δ , q 1 , F ) be a DFA recognizing language A and let p be the number of states of M .

s = s 1 s 2 …s n是属于A的长度为n的单词,其中np。令r 1 , …, r n +1为M在处理s期间进入的状态序列,因此r i +1 = δ ( r i , s i ),其中 1 ≤ in。该序列的长度为n + 1,即至少p + 1。根据鸽笼规则,在序列r 1 , ..., r n +1的前p + 1 个元素中,至少有两个状态必须相同。我们将第一个称为r j,将第二个称为r l。由于r l出现在以r 1开头的单词的前p + 1 个位置之一,因此我们得到lp + 1。现在令x = s 1 …s j −1y = s j …s l −1z = s l …s n

Let s = s 1 s 2 …s n be a word of length n in A , where np . Let r 1 , …, r n +1 be a sequence of states that M enters while processing s , such that r i +1 = δ ( r i , s i ) for 1 ≤ in . This sequence has length n + 1, that is, at least p + 1. By the pigeonhole principle, among the first p + 1 elements of the sequence r 1 , …, r n +1 at least two states must be identical. Let us call the first of them r j , and the second r l . Since r l occurs in one of the first p +1 positions of the word starting with r 1 , we get lp +1. Now let x = s 1 …s j −1 , y = s j …s l −1 and z = s l …s n .

由于xM从状态r 1转移到r jyM从状态r j转移到r jzr j转移到r n +1(这是接受状态),因此当i ≥ 0 时, M必须接受xyz。我们知道j l,所以 | y | > 0;我们还知道lp +1,所以 | XY | ≤ p。这样,我们就满足了泵送引理的所有条件。

Since x takes M from state r 1 to r j , y takes M from r j to r j , and z from r j to r n +1 , which is an accepting state, M must accept xy and z for i ≥ 0. We know that j l , so | y | > 0; we also know that lp +1, so | xy | ≤ p . We have thus satisfied all the conditions of the Pumping Lemma.

为了使用泵引理来证明语言B不是正则的,我们首先假设B是正则的,从而导致矛盾。然后我们使用泵引理,它保证存在泵长度p,使得属于B且长度等于p或更大的每个单词都可以被膨胀。然后我们找到一个长度为p或更大且不能膨胀的单词s 。最后,我们表明,在给定将s划分为xyz部分的所有方式的情况下,单词s不能被泵送(如果方便的话,考虑泵送引理的条件 3),并且对于每个这样的分区,我们找到 的值i使得xyz B。最后一步通常涉及将不同的划分方式分组为不同的情况并单独分析它们。s 的存在与泵引理相矛盾,如果语言B是正则的,泵引理就必须成立。由此可见B不可能是正则语言。

To use the Pumping Lemma to show that a language B is not regular, we first assume that B is regular to achieve a contradiction. We then use the Pumping Lemma, which guarantees the existence of a pumping length p such that every word of length p or greater in B can be pumped. We then find a word s of length p or greater that cannot be pumped. Finally, we show that the word s cannot be pumped, given all the ways of partitioning s into parts x , y , and z (taking into account condition 3 of the Pumping Lemma, if convenient), and for each such partition we find a value for i such that x y and z B . This final step often requires grouping the different ways of partitioning s into different cases and analyzing them individually. The existence of s contradicts the Pumping Lemma, which would have to hold if B were regular. It follows that B cannot be a regular language.

寻找s有时需要一些创造性思维。在找到一个有效的候选者之前,您可能需要尝试许多候选者值得尝试的B元素似乎代表了B非正则性的“本质”。我们将在以下一些示例中进一步讨论搜索任务

Finding s sometimes requires a bit of creative thinking. You may need to try many candidates for s before you find one that works. It is worth trying out elements of B that seem to represent the “essence” of the irregularity of B . We will discuss the task of finding s further in some of the following examples.

实施例 1.73

Example 1.73

B为语言 { 0 n 1 n : n ≥ 0}。我们将使用泵引理来证明B不是正则语言。通过制造矛盾来证明。

Let B be a language { 0 n 1 n : n ≥ 0}. We use the pumping lemma to prove that B is not a regular language. The proof follows by contradiction.

假设B是正则的。令p为由泵浦引理得出的泵浦长度。作为s,我们选择单词 0 p 1 p。由于s属于B并且长度大于p,泵送引理保证s可以分为三部分,s = xyz,这样对于任何i ≥ 0,单词xyz属于B。我们将考虑三种情况来证明这样的结果是不可能的。

Assume that B is regular. Let p be the pumping length that follows from the Pumping Lemma. We choose s to be the word 0 p 1 p . Since s belongs to B and has length greater than p , the Pumping Lemma guarantees that s can be partitioned into three parts, s = xyz , such that for any i ≥ 0 the words xy and z also belong to B . We consider three cases to show that such a result is impossible.

  1. 由全零组成的子字y 。在这种情况下,单词xyyz的 0 多于 1,因此不是B 的元素,这违反了泵引理的条件 1。这个案例就导致了一个矛盾。
  2. A subword y consisting of all zeros. In this case, the word xyyz has more zeros than ones and thus is not an element of B , which violates condition 1 of the Pumping Lemma. This case leads to a contradiction.
  3. 子词y仅由 1 组成 - 类比推理使我们陷入矛盾。
  4. The subword y is composed of only ones – analogous reasoning leads us to a contradiction.
  5. 子字y由 0 和 1 组成。在这种情况下,单词xyyz可能包含相同数量的 0 和 1,但它们不会被排序,即一些 1 将出现在一些 0 之前。因此,它不是语言B的元素,这意味着矛盾。
  6. The subword y consists of both zeros and ones. In this case, the word xyyz can contain the same number of zeros and ones, but they will not be in order, i.e. some ones will come before some zeros. Thus, it is not an element of the language B , which means a contradiction.

由于假设 B 是正则语言会导致矛盾,因此我们得出结论 B 不是正则语言。请注意,我们可以通过使用泵引理的条件 3 来消除情况 2 和 3 来简化该论证。

Since the assumption that B is regular leads to a contradiction, we conclude that B is not a regular language. Note that we can simplify this argument by using condition 3 of the pumping lemma to eliminate cases 2 and 3.

在这个例子中,找到单词s很容易,因为B中任何长度为p或更大的单词都会不一致。在接下来的两个示例中,某些s字选择将不起作用,因此需要付出额外的努力。

In this example, finding s was easy, since any word in B of length p or greater will show the contradiction. In the next two examples, some choices of s will not work, so additional effort is required.

实施例 1.74

Example 1.74

C = { w : w包含相同数量的 0 和 1}。我们将使用泵引理来证明C不是正则语言。证明将通过还原为矛盾来进行。

Let C = { w : w contains an equal number of zeros and ones}. We use the pumping lemma to show that C is not a regular language. The proof follows by reduction to contradiction.

相反,假设C是正则的。令p为由泵浦引理得出的泵浦长度。如示例 1.73 所示,令s为单词0 p 1 p。由于s是C的成员并且长度大于p,泵送引理保证s可以分为三部分,s = xyz,这样对于任何 ≥  0,单词xyz也属于C。我们想要表明这样的结果是不可能的。但是等等,这是可能的!如果我们假设xz是空词,y是词0 p 1 p,则xyz始终具有相同数量的 0 和 1,因此属于C。所以看起来s可以膨胀。

Suppose, on the contrary, that C is regular. Let p be the pumping length that follows from the Pumping Lemma. As in Example 1.73, let s be the word 0 p 1 p . Since s is a member of C and has length greater than p , the Pumping Lemma guarantees that s can be partitioned into three parts, s = xyz , such that for any ≥  0 , the word xy and z also belong to C . We intend to show that such a result is impossible. But wait, it is possible! If we assume that x and z are empty words and y is the word 0 p 1 p , then xy and z always have an equal number of zeros and ones, and thus belong to C . So it looks like s can be pumped.

这就是泵送引理的条件 3 发挥作用的地方。它强制要求在泵送单词s时,必须将其拆分,以便 | XY | ≤ p。对s如何划分的这种限制很容易表明我们选择的单词s = 0 p 1 p不能被夸大。如果 | XY | ≤ p,这意味着y必须由全零组成,因此xyyz C。因此,s不能被泵浦,这给我们带来了所需的矛盾。

This is where Condition 3 of the Pumping Lemma comes in handy. It dictates that if a word s is pumped , it must be partitioned so that | xy | ≤ p . This restriction on the way s is partitioned makes it easy to show that our chosen word s = 0 p 1 p cannot be pumped. If | xy | ≤ p , this means that y must consist of all zeros, so xyyz C . Hence s cannot be pumped, which gives us the desired contradiction.

在本例中选择s字需要比例 1.73 中更多的努力。例如,如果我们选择s = ( 01 ) p,我们可能会遇到麻烦,因为我们需要找到一个不能膨胀的单词,并且即使给定条件 3,这个特定的单词也可以膨胀。你能看到它是如何膨胀的吗?一种方法是设置x = εy = 01z = ( 01 ) p −1。然后对于每个单词xyz C。如果您第一次未能找到一个无法夸大的单词,请不要绝望,而是尝试另一个单词!

Choosing the word s in this example required more effort than in Example 1.73. For example, if we had chosen s = ( 01 ) p , we might have run into trouble, since we need to find a word that cannot be inflated, and this particular word can be inflated even under Condition 3. Can you see how it can be inflated? One way to do this is to set x = ε , y = 01 , and z = ( 01 ) p −1 . Then for each i word xy and z C . If you don't find a word that cannot be inflated on the first try, don't despair, but try another one!

证明C非正则的另一种方法是根据我们对B非正则的知识得出的。如果C是正则的,则C 0 * 1 *也将是正则的。这是因为语言0 * 1 *是正则语言,正则语言的类由于交集而封闭,正如我们在脚注 3(第 46 页)中所示。然而,C 0 * 1 *等于B,并且我们从例 1.73 中已经知道B不是正则的。

An alternative way of proving that C is not regular follows from our knowledge that B is not regular. If C were regular, C 0 * 1 * would also be regular. This follows from the fact that the language 0 * 1 * is regular and the class of regular languages ​​is closed under intersection, as we showed in footnote 3 (page 46). However, C 0 * 1 * is equal to B , and we already know from Example 1.73 that B is not regular.

实施例 1.75

Example 1.75

F = { ww : w { 0 , 1 } * }。我们将使用泵引理证明F不是正则语言。

Let F = { ww : w { 0 , 1 } * }. We will show that F is not a regular language using the pumping lemma.

为了证明的目的,我们隐含地假设F是正则的。令p为由泵浦引理得出的泵浦长度。令s为单词0 p 10 p 1。由于s属于F并且s的长度大于p,因此泵送引理保证s可以分为三部分,s = xyz,满足引理的三个条件。我们将证明这样的结果是不可能的。

For the sake of proof, we assume that F is regular. Let p be the pumping length that follows from the Pumping Lemma. Let s be the word 0 p 10 p 1 . Since s is a member of F and s has length greater than p , the Pumping Lemma guarantees that s can be partitioned into three parts, s = xyz , satisfying the three conditions of the lemma. We will show that such a result is impossible.

条件 3 再次被证明是至关重要的,因为没有它我们可以泵 s,假设xz是空字。由于条件 3,证明与前一个类似,因为y必须仅由零组成,因此xyyz F

Condition 3 is once again crucial, since without it we could pump  s by assuming that x and z are empty words. Thanks to Condition 3, the proof is analogous to the previous one, since y must consist of all zeros, therefore xyyz F .

请注意,我们选择s = 0 p 10 p 1作为代表非正则性F的“本质”的单词,而不是例如单词0 p 0 p。即使0 p 0 p属于F,也不可能证明矛盾,因为它可以被泵浦。

Note that we have chosen s = 0 p 10 p 1 as the word representing the “essence” of the irregularity F , in contrast to, for example, the word 0 p 0 p . Even though 0 p 0 p belongs to F , we will not be able to demonstrate a contradiction with it, since it can be pumped up.

实施例 1.76

Example 1.76

我们将展示一种非正则的一元语言。令D = { 1 n 2 : n ≥ 0}。换句话说,D包含所有由长度为自然数平方的单词组成的单词。我们将使用泵引理来证明D不是正则语言。通过制造矛盾来证明。

We will show an irregular unary language. Let D = { 1 n 2 : n ≥ 0}. In other words, D contains all words built of ones whose lengths are squares of natural numbers. We will use the pumping lemma to show that D is not a regular language. The proof follows by contradiction.

假设D是正则语言。令p为由泵浦引理得出的泵浦长度。让s成为单词1 p 2。由于s是D的元素,并且s的长度至少为p,因此泵送引理保证s可以分为三部分,s = xyz,满足引理的三个条件。与前面的示例一样,我们将证明这样的结果是不可能的。这需要对自然数的平方序列进行思考:

Assume D is a regular language. Let p be the pumping length that follows from the Pumping Lemma. Let s be a word 1 p 2 . Since s is an element of D and the length of s is at least p , the Pumping Lemma guarantees that s can be partitioned into three parts, s = xyz , satisfying the three conditions of the lemma. As in the previous examples, we will show that such a result is impossible. This requires a moment's thought about the sequence of squares of natural numbers:

0, 1, 4, 9, 16, 25, 36, 49, …

0, 1, 4, 9, 16, 25, 36, 49, …

让我们注意该序列的后续元素之间不断增加的差异。该序列的大元素不能彼此靠近。

Notice the increasing differences between successive elements of this sequence. Large elements of this sequence cannot be close to each other.

现在考虑两个单词xyzxy 2 z。这些单词因y 的一次重复而彼此不同,因此它们的长度也因y的长度而不同。从泵送引理的条件 3 | XY | ≤ p,因此 | y | ≤ p。所以我们有 | XYZ | = p 2和 | XY 2 Z | ≤ p 2 + p。但p 2 + p < p 2 +2 p +1 = ( p +1) 2。此外,条件 2 意味着y不能是空词,因此 | XY 2 Z | >第2。因此,字长xy 2 z位于两个连续的方格p 2和( p +1) 2之间。因此,长度本身不可能是整数的平方。因此,我们得出了xy 2D 的矛盾,并得出语言D不是正则的结论。

Now consider two words xyz and xy 2 z . These words differ from each other by a single repetition y , and consequently their lengths differ by length y . By condition 3 of the Pumping Lemma, | xy | ≤ p , and therefore | y | ≤ p . We thus have | xyz | = p 2 and | xy 2 z | ≤ p 2 + p . But p 2 + p < p 2 +2 p +1 = ( p +1) 2 . Moreover, by condition 2 it follows that y cannot be the empty word, and therefore | xy 2 z | > p 2 . Thus the length of the word xy 2 z lies between two consecutive squares p 2 and ( p + 1) 2 . Hence this length cannot itself be an integer square. We have thus reached the contradiction xy 2 z D and we conclude that the language D is not regular.

1.77

Example 1.77

有时,在应用抽吸引理时,“抽吸”很有用。我们将使用泵引理来证明语言E = { 0 i 1 j : i > j } 是非正则的。通过制造矛盾来证明。

Sometimes it is useful to "pump down" when applying the Pumping Lemma. We will use the Pumping Lemma to show that the language E = { 0 i 1 j : i > j } is not regular. The proof follows by contradiction.

假设E是正则语言。令p为由泵浦引理得出的泵浦长度E。s = 0 p +1 1 p。然后s可以分为单词xyz,满足引理的条件。根据条件 3,y由全零组成。让我们检查一下单词xyyz,看看它是否可以属于E。附加y的额外副本会增加零的数量。然而,E包含属于0 * 1 *的所有单词,其中包含的 0 多于 1,因此增加 0 的数量仍然会产生属于E 的单词。这里并不矛盾。我们必须尝试一些不同的东西。

Suppose E is a regular language. Let p be the pumping length of E , which follows from the Pumping Lemma. Let s = 0 p + 1 1 p . Then s can be partitioned into words xyz , which satisfy the conditions of the lemma. By Condition 3, y consists of all zeros. Let us examine the word xyyz to see if it can be a member of E . Appending an additional copy of y increases the number of zeros. However, E contains all the words in 0 * 1 * , which contain more zeros than ones, so increasing the number of zeros still gives a word in E . There is no contradiction here. We have to try something else.

泵引理指出,即使当i = 0 时, xy i z E也如此,所以让我们尝试考虑xy 0 z = xz。删除单词y会减少s中零的数量。然而,回想一下,s只包含比 1 多 1 个的 0。因此,xz 的0不能多于 1,因此不能属于E。这就是我们如何得到矛盾的原因。

The pumping lemma states that xy i z E even when i = 0, so let's consider xy 0 z = xz . Removing the term y reduces the number of zeros in s . Recall, however, that s contains only one more zero than ones. Therefore, xz cannot have more zeros than ones, and therefore cannot belong to E . This gives us a contradiction.

练习

Exercises

A 1.1下面显示的是两个DFA M 1M 2 的状态图。回答以下关于这些机器的问题。

A 1.1 Shown below are state diagrams of two DFAs M 1 and M 2 . Answer the following questions about these machines.

a. 初始状态是什么?

a. What is the initial state?

b. 接受状态的集合是什么?

b. What is the set of accepting states?

c.机器在处理aabb输入 时经历什么状态序列?

c. What sequence of states does the machine go through when processing input aabb ?

d. 机器接受单词aabb吗?

d. Does the machine accept the word aabb ?

e. 机器接受单词ε吗?

e. Does the machine accept the word ε ?

A 1.2给出练习 1.1 中所示 机器M 1M 2的正式描述。

A 1.2 Give a formal description of the machines M 1 and M 2 presented in exercise 1.1.

1.3 DFA M 的形式化描述为({ q 1 , q 2 , q 3 , q 4 , q 5 }, { u , d }, δ , q 3 , { q 3 }),其中δ由表定义以下。提供该机器的状态图。

1.3 The formal description of the DFA M is ({ q 1 , q 2 , q 3 , q 4 , q 5 }, { u , d }, δ , q 3 , { q 3 }), where δ is defined by the table below. Give a state diagram for this machine.

at

d

d

q 1

q1

q 1

q1

q 2

q2

q 2

q2

q 1

q1

q 3

q3

q 3

q3

q 2

q2

q 4

q4

q 4

q4

q 3

q3

q 5

q5

q 5

q5

q 4

q4

q 5

q5

1.4 以下每种语言都是两种更简单语言的交集(共同)。在每一点,为更简单的语言构建一个 DFA,然后使用脚注 3(第 46 页)中描述的结构将它们组合起来,以表示给定语言的 DFA 状态图。在所有点Σ = { a , b }。

1.4 Each of the following languages ​​is the intersection of two simpler languages. At each point, construct a DFA for the simpler languages, and then combine them using the construction described in footnote 3 (page 46) to represent a DFA state diagram for the given language. At all points, Σ = { a , b }.

a. { w : w包含至少两个a和至少两个b }

a. { w : w contains at least two a's and at least two b's }

A b. { w : w恰好包含两个a和至少两个b }

A b. { w : w contains exactly two a's and at least two b's }

c. { w : w包含一个偶数a和一个或两个b }

c. { w : w contains an even number of a's and one or two b's }

A d. { w : w包含偶数个a,每个a后面至少有一个b }

A d. { w : w contains an even number of a , where each a is followed by at least one b }

e. { w : w以a开头,最多包含一个b }

e. { w : w starts with a and contains at most one b }

f. { w : w包含奇数a并以b结尾}

f. { w : w contains an odd number of a's and ends with b }

g. { w : w具有偶数长度并包含奇数a }

g. { w : w has even length and contains an odd number of a }

1.5 以下每种语言都是更简单语言的补充。在每一点,为更简单的语言构建一个 DFA,然后用它来表示给定语言的 DFA 的状态图。在所有点Σ = { a , b }。

1.5 Each of the following languages ​​is the complement of a simpler language. At each point, construct a DFA for the simpler language, and then use it to represent a DFA state diagram for the given language. At all points, Σ = { a , b }.

A a. { w : w不包含子词ab }

A a. { w : w does not contain the subword ab }

A b. { w : w不包含子词baba }

A b. { w : w does not contain the subword baba }

c. { w : w不包含任何子串abba }

c. { w : w does not contain any of the substrings ab or ba }

d. { w : w是不属于a * b *的任何单词}

d. { w : w is any word not belonging to a * b * }

e. { w : w是不属于 ( ab + ) *的任何单词}

e. { w : w is any word not belonging to ( ab + ) * }

f. { w : w是不属于a * b *的任何单词}

f. { w : w is any word not belonging to a * b * }

g. { w : w是任何不包含两个a 的单词}

g. { w : w is any word that does not contain exactly two a's }

h. { w : w是除a和 b之外的任何单词}

h. { w : w is any word except a and  b }

1.6 提供识别以下语言的 DFA 的状态图。在所有点上,字母表都是 { 0 , 1 }。

1.6 Give state diagrams for DFAs that recognize the following languages. At all points the alphabet is { 0 , 1 }.

a. { w : w以1开头,以0结尾}

a. { w : w starts with 1 and ends with 0 }

b. { w : w至少包含三个1 }

b. { w : w contains at least three 1 }

c. { w : w包含子字0101(即w = x 0101 y对于某些xy)}

c. { w : w contains the substring 0101 (i.e. w = x 0101 y for some x and y )}

d. { w : w的长度至少为 3 并且其第三个符号为0 }

d. { w : w has length at least 3 and its third symbol is 0 }

e. { w : w0开始并且具有奇数长度或从1开始并且具有偶数长度}

e. { w : w starts from 0 and has odd length or starts from 1 and has even length}

f. { w : w不包含子字110 }

f. { w : w does not contain subword 110 }

g. { w : w的长度最多为 5}

g. { w : length of w is at most 5}

h. { w : w是除11111之外的任何单词}

h. { w : w is any word except 11 and 111 }

i. { w : w 中的每个奇数位置都是1 }

i. { w : every odd position in w is 1 }

j. { w : w至少包含两个0,最多一个1 }

j. { w : w contains at least two 0s and at most one 1 }

k. { ε , 0 }

k. { ε , 0 }

l. { w : w包含偶数0或恰好包含两个1 }

l. { w : w contains an even number of 0s or contains exactly two 1s }

m. Empty set

名词 除空白外的所有单词

n . All words except empty

1.7 提供 NFA 的状态图,以识别包含给定数量状态的每种语言。在所有点上,字母表都是 { 0 , 1 }。

1.7 Give state diagrams for NFAs recognizing each of the languages ​​shown, containing the given number of states. At all points, the alphabet is { 0 , 1 }.

A a. 语言 { w : w以00结尾} 具有三种状态

A a. Language { w : w ends with 00 } with three states

b. 练习 1.6 中的语言有五种状态

b. The language from exercise 1.6c with five states

c. 练习 1.6l 中的语言有六种状态

c. The language from exercise 1.6l with six states

d.具有两种状态的 语言{0}

d. Language { 0 } with two states

e. 语言0 * 1 * 0 +具有三种状态

e. Language 0 * 1 * 0 + with three states

A f. 语言1 * ( 001 + ) *具有三种状态

A f. Language 1 * ( 001 + ) * with three states

g.具有一种状态的 { ε } 语言

g. Language { ε } with one state

h. 语言0 *具有一种状态

h. Language 0 * with one state

1.8 使用定理 1.45 的证明中所示的结构,提供识别 中描述的语言之和的 NFA 的状态图

1.8 Use the construction given in the proof of Theorem 1.45 to give state diagrams of NFAs recognizing the union of languages ​​described in

练习 1.6a 和 1.6b。

a. exercises 1.6a and 1.6b.

b. 练习 1.6c 和 1.6f。

b. exercises 1.6c and 1.6f.

1.9 使用定理 1.47 的证明中所示的结构提供识别中描述的语言串联的 NFA 状态图

1.9 Use the construction shown in the proof of Theorem 1.47 to give state diagrams of NFAs that recognize concatenation of the languages ​​described in

a. 练习 1.6g 和 1.6i。

a. exercises 1.6g and 1.6i.

b. 练习 1.6b 和 1.6m。

b. exercises 1.6b and 1.6m.

1.10 使用定理 1.49 证明中所示的结构提供识别 Kleene 闭包中描述的语言的NFA 状态图

1.10 Use the construction shown in the proof of Theorem 1.49 to give state diagrams of NFAs recognizing Kleene closure of the languages ​​described in

练习 1.6b。

a. exercise 1.6b.

练习1.6j

b. exercise 1.6j.

c. 练习1.6m。

c. exercise 1.6m.

A 1.11 证明任何NFA都可以转换为仅包含一个接受状态的等效非确定性有限状态机。

A 1.11 Prove that every NFA can be converted into an equivalent nondeterministic finite automaton containing only one accepting state.

1.12D = { w : w包含偶数a和奇数b并且不包含子字ab }。提供识别语言D 的五态 DFA 和生成D的正则表达式。 (建议:尝试用更简单的方式描述D语言。)

1.12 Let D = { w : w contains an even number of a's and an odd number of b's and does not contain a substring ab }. Give a five-state DFA that recognizes the language D and a regular expression that generates D . (Suggestion: try to describe the language D in a simpler way.)

1.13F为字母表 { 0 , 1 } 上所有单词的语言,使得它们不包含由奇数个符号分隔的成对单词。提供识别F的五状态 DFA 的状态图。 (首先找到F 的补码的四状态 NFA 可能会有所帮助。)

1.13 Let F be the language of all words over the alphabet { 0 , 1 } such that they contain no pairs of ones separated by an odd number of symbols. Give a state diagram of a five-state DFA that recognizes F . (It may be helpful to first find a four-state NFA for the complement of F .)

1.14 a. 证明如果M是识别语言B 的DFA ,则交换M的接受和不接受状态给出一个识别语言B的补语的新 DFA 。由此推论,正则语言的类对于补码是闭集的。

1.14 a. Show that if M is a DFA recognizing language B , interchanging the accepting and nonaccepting states of M gives a new DFA recognizing the complement of language B . Conclude from this that the class of regular languages ​​is closed under complement.

b. 通过例子证明,如果M是一个识别语言C的 NFA ,则交换接受和不接受状态不一定会产生一个识别语言C的补集的新 NFA。 NFA认可的语言类别是否因互补而封闭?解释一下答案。

(b) Show by example that if M is an NFA that recognizes the language C , swapping the accepting and nonaccepting states does not necessarily produce a new NFA that recognizes the complement of C . Is the class of languages ​​recognized by an NFA closed under complement? Explain your answer.

1.15 给出一个反例,说明下面的构造不能证明定理1.49,即正则语言的类由于星号操作而封闭7。令N 1 = ( Q 1 , Σ , δ 1 , q 1 , F 1 ) 识别语言A 1。我们构造N = ( Q 1 , Σ , δ , q 1 , F ) 如下。N应该识别语言A * 1

1.15 Give a counterexample to show that the following construction does not allow us to prove Theorem 1.49 that the class of regular languages ​​is closed under the asterisk operation 7 . Let N 1 = ( Q 1 , Σ , δ 1 , q 1 , F 1 ) recognize the language A 1 . We construct N = ( Q 1 , Σ , δ , q 1 , F ) as follows. N is to recognize the language A * 1 .

a. N 个 状态是N 1 个状态。

a. The N states are N 1 states .

b. 初始状态N与初始状态N 1相同。

b. The initial state of N is the same as the initial state of N 1 .

c. F = { q 1 } F 1

c. F = { q 1 } F 1 .

接受状态集合F由旧接受状态和初始状态组成。

The set of accepting states F consists of the old accepting states and the initial state.

d. 我们定义δ,使得对于任何q Q 1和任何a Σ ε

d. We define δ so that for any q Q 1 and any a Σ ε ,

(建议:以图形方式显示此结构,如图 1.50 所示。)

(Suggestion: Show this construction graphically, as in Figure 1.50.)

1.16 使用定理 1.39 中给出的构造将以下两个非确定性有限自动机转换为等效的确定性有限自动机。

1.16 Use the construction in Theorem 1.39 to convert the following two nondeterministic finite-state machines into equivalent deterministic finite-state machines.

1.17 a.提供可识别语言 ( 01 001 010 ) * 的 NFA 。

1.17 a. Provide an NFA that recognizes the language ( 01 001 010 ) * .

b. 将此 NFA 转换为等效的 DFA。仅表示 DFA 中从初始状态可到达的部分。

b. Transform this NFA into an equivalent DFA. Show only the part of the DFA that is reachable from the initial state.

1.18 陈述生成练习1.6中语言的正则表达式。

1.18 Give the regular expressions that generate the languages ​​from Exercise 1.6.

1.19 使用引理 1.55 中描述的过程将以下正则表达式转换为非确定性有限自动机。

1.19 Use the procedure in Lemma 1.55 to transform the following regular expressions into nondeterministic finite automata.

( 0 1 ) * 000 ( 0 1 ) *

a. ( 0 1 ) * 000 ( 0 1 ) *

b. ((( 00 ) * ( 11 )) 01 ) *

b. ((( 00 ) * ( 11 )) 01 ) *

什么 *

What *

1.20 对于以下每种语言,给出两个属于成员的单词和两个不是成员的单词 - 每点总共四个单词。假设字母表Σ  = { a , b } 在所有点上。

1.20 For each of the following languages, give two words that are members of it and two that are not members of it – four words in total for each point. Assume that the alphabet Σ  = { a , b } at all points.

a.a * b *

a. a * b *

b. a( ba ) * b。

b. a( ba ) * b

c. a * b *

c. a * b *

d.aaa*

d. ( aaa ) *

e. Σ * a Σ * b Σ * a Σ *

e. Σ * a Σ * b Σ * a Σ *

f . 巴布

f. a ba bab

g. ( ε a ) b。

g. ( ε a ) b

h. ( a ba bb ) Σ *

h. ( a ba bb ) Σ *

1.21 使用引理 1.60 中描述的过程将以下有限自动机转换为正则表达式。

1.21 Use the procedure in Lemma 1.60 to transform the following finite automata into regular expressions.

1.22 在某些编程语言中,注释出现在分隔符之间,例如/##/。令C为所有有效限制注释词的语言。成员C必须以/#开头并以#/结尾,但其中不包含子词#/。为简单起见,假设C的字母表为Σ = { a , b , / , # }。

1.22 In some programming languages, comments appear between delimiters such as /# and #/ . Let C be the language of all valid delimited comment words. A member of C must begin with /# and end with #/ , but without an intervening subword #/ . For simplicity, assume that the alphabet of C is Σ = { a , b , / , # }.

a.提供可识别C 的 DFA 。

a. Provide a DFA that recognizes C .

b.指定生成C 的正则表达式。

b. Enter a regular expression that generates C .

A 1.23B为字母表Σ上的任何语言。证明B = B +当且仅当BB B。

A 1.23 Let B be an arbitrary language over the alphabet Σ . Prove that B = B + if and only if BB B .

1.24 有限状态转换器 FST )是一种确定性有限自动机,其输出是某个单词,而不仅仅是接受拒绝输入单词。T 1T 2有限换能器的状态图如下所示。

1.24 A finite state transducer ( FST) is a type of deterministic finite state machine whose output is a word rather than merely accepting or rejecting an input word. State diagrams of finite state transducers T 1 and T 2 are shown below .

FST 中的每个转换由两个符号描述,其中一个表示该转换的输入符号,另一个表示输出符号。这两个符号由斜杠 / 分隔。在T 1 处,从状态q 1q 2的转变具有输入符号2和输出符号1。一些转换可能包含多个输入输出对,例如,机器T 1中从q 1到其自身的转换。当FST处理输入字w时,它一一读取输入符号w 1 ... w n,并从初始状态开始,执行与读取的符号w 1 ... w n = w匹配的转换。对于每个转换,它都会打印与该转换相对应的输出符号。例如,对于输入2212011,机器T 1经历状态序列q 1 , q 2 , q 2 , q 2 , q 2 , q 1 , q 1 , q 1并产生输出1111000。机器T 2对于输入abbb返回1011。为以下每个点提供状态字符串和返回的输出。

Each transition in the FST is described by two symbols, one of which designates the input symbol for the transition, and the other of which designates the output symbol. The two symbols are separated by a slash character, /. In T 1 , the transition from state q 1 to q 2 has input symbol 2 and output symbol 1 . Some transitions may contain multiple input-output pairs, e.g., the transition from q 1 to itself in machine T 1 . When the FST processes the input word w , it reads the input symbols w 1w n in turn and, starting from the initial state, performs the transitions that match the symbols read w 1w n = w . For each transition, it prints out the output symbol corresponding to the transition. For example, for input 2212011 , machine T 1 traverses the sequence of states q 1 , q 2 , q 2 , q 2 , q 1 , q 1 , q 1 and produces the output 1111000 . Machine T 2 for input abbb returns 1011 . Give the sequence of states and the returned output for each of the following points.

a. T 1用于输入011

a. T 1 for input 011

b. T 1用于输入211

b. T 1 for input 211

c. T 1用于输入121

c. T 1 for input 121

d. T 1用于输入0202

d. T 1 for input 0202

e. T 2用于输入b

e. T 2 for input b

f. T 2输入bbab

f. T 2 for input bbab

g. T 2输入bbbbbb

g. T 2 for input bbbbbb

h. 输入ε的T 2

h. T 2 for input ε

1.25 阅读练习 1.24 中有限传感器的非正式定义。按照定义 1.5(第 35 页)中的模式提供此模型的正式定义。假设 FST 有一个输入字母表Σ和一个输出字母表Γ,但没有一组接受状态。包括 FST 执行的计算的正式定义。 (提示:FST 是有序五。其传递函数的形式为δ : Q × ΣQ × Γ。

1.25 Read the informal definition of a finite-state transducer in Exercise 1.24. Give a formal definition of this model using the pattern in Definition 1.5 (page 35). Assume that the FST has an input alphabet Σ and an output alphabet Γ , but no set of accepting states. Consider the formal definition of the computations performed by the FST. (Hint: The FST is an ordered quintuplet. Its transfer function is of the form δ : Q × ΣQ × Γ . )

1.26使用练习 1.25 的解决方案,对练习 1.24 中所示的 机器T 1T 2进行正式描述。

1.26 Using the solution to Exercise 1.25, give a formal description of the machines T 1 and T 2 illustrated in Exercise 1.24.

1.27 阅读练习 1.24 中有限传感器的非正式定义。提供具有以下行为的 FST 状态图。它的输入和输出字母表是{ 0 , 1 }。其输出字在偶数位置与输入字相同,但在奇数位置包含反向符号。例如,对于输入0000111,此 FST 应返回1010010

1.27 Read the informal definition of a finite-state transducer in Exercise 1.24. Give a state diagram of an FST with the following behavior. Its input and output alphabets are { 0 , 1 }. Its output word is identical to the input in even positions but contains inverse symbols in odd positions. For example, for an input of 0000111, this FST should return 1010010 .

1.28 使用定理 1.54 中描述的过程将以下正则表达式转换为 NFA。在所有点Σ = { a , b }。

1.28 Convert the following regular expressions to NFAs using the procedure in Theorem 1.54. At all points Σ = { a , b }.

a. a( abb ) * b

a. a( abb ) * b

b. a + ( ab ) +

b. a + ( ab ) +

( a b + ) a + b +

c. ( a b + ) a + b +

1.29 使用泵引理证明下列语言不是正则语言。

1.29 Use the pumping lemma to show that the following languages ​​are not regular.

A a 1 = { 0 n 1 n 2 n : n ≥ 0}

A a. A 1 = { 0 n 1 n 2 n : n ≥ 0}

b. A 2 = { www : w { a , b } * }

b. A 2 = { www : w { a , b } * }

A c. A 3 = { a 2 n : n ≥ 0} (这里a 2 n表示 2 n个字符a的单词。)

A c. A 3 = { a 2 n : n ≥ 0} (Here a 2 n means a word composed of 2n characters a . )

1.30 解释下列“证明”中的错误:0 * 1 *不是正则语言(这个错误一定存在,因为语言0 * 1 * 正则语言)。证据是间接的。假设0 * 1 *是正则的。令p为0 * 1 *的泵浦长度,由泵浦引理得出。作为s,我们选择单词0 p 1 p。我们知道s是0 * 1 *的元素,但示例 1.73 表明s不能被泵浦。我们得到了一个矛盾,所以0 * 1 *不是正则语言。

1.30 Explain the error in the following "proof" that 0 * 1 * is not a regular language (such an error must exist, since the language 0 * 1 * is regular). Proof by contradiction. Assume that 0 * 1 * is regular. Let p be the pumping length of 0 * 1 * , which follows from the Pumping Lemma. We choose s as the word 0 p 1 p . We know that s is an element of 0 * 1 * , but Example 1.73 shows that s cannot be pumped. We get a contradiction, so 0 * 1 * is not a regular language.

任务

Tasks

1.31 对于任何单词w = w 1 w 2 …w n w 的 ,写为w R,是包含逆序符号w n …w 2 w 1 的单词。对于任何语言A,A R = { w R : w A }。证明如果A是正则,则A R也是正则。

1.31 For any word w = w 1 w 2 …w n , the inverse of w , written as w R , is the word containing the symbols in the reverse order, w n …w 2 w 1 . For any language A, let A R = { w R : w A }. Show that if A is regular, then A R is also regular.

1.32

1.32 Let

Σ 3包含大小为 3 的所有列向量,由 0 和 1 组成。带有Σ 3 的符号字给出三行 0 和 1。让我们假设每一行都是一个二进制数,并让

Σ 3 contains all column vectors of size 3, consisting of zeros and ones. The symbol word of Σ 3 gives three rows of zeros and ones. Assume that each row is a binary number and let

B = { w Σ 3 * : w 的底行是顶两行的总和}。

B = { w Σ 3 * : the bottom row of w is the sum of the top two rows }.

例如

For example

证明B是正则语言。 (提示:使用 BR 语言会更容易可以假设问题 1.31 中声明的结果。)

Prove that B is a regular language. (Hint: it will be easier to work with the language B R ; you can assume the result declared in Exercise 1.31.)

1.33

1.33 Let

在此示例中,Σ 2包含高度为 2 的所有零和一的列向量。Σ 2的符号字产生两行零和一。让我们假设每一行都是一个二进制数,并让

In this example, Σ 2 contains all column vectors of zeros and ones of height two. The symbol word of Σ 2 forms two rows of zeros and ones. Assume that each row is a binary number and let

C = { w Σ 2 * : w 的底行是顶行的三倍}。

C = { w Σ 2 * : the bottom row of w is triple the top row}.

例如

For example

证明C语言是正则的。 (你可以接受问题1.31中声明的结果作为已证明的结果。)

1.34Σ 2与问题 1.33 中的字母表相同。让我们假设每一行都是一个二进制数,并让

1.34 Let Σ 2 be the same alphabet as in Problem 1.33. Assume that each row is a binary number and let

D = { w Σ 2 *:顶行是大于底行的数字}。

D = { w Σ 2 * : top row is a number greater than bottom row}.

例如

For example

证明D是正则语言。

1.35Σ 2与问题 1.33 中的字母表相同。假设顶行和底行是由 0 和 1 组成的单词,然后让

1.35 Let Σ 2 be the same alphabet as in Problem 1.33. Assume that the top and bottom rows are words of zeros and ones, and let

E = { w Σ 2 * : w的底线是w顶线的倒数}。

E = { w Σ 2 * : the bottom row of w is the inverse of the top row of w }.

证明语言E不是正则语言。

Show that the language E is not regular.

1.36B n = {kk是n 的倍数}。证明对于每个n ≥ 1,语言B n是正则的。

1.36 Let B n = { a k : k is a multiple of n }. Prove that for every n ≥ 1 the language B n is regular.

1.37C n = { x : x是一个二进制数,是n的倍数}。证明对于每个n ≥ 1,C语言n都是正则的。

1.37 Let C n = { x : x be a binary number that is a multiple of n }. Show that for every n ≥ 1 the language C n is regular.

1.38 All-NFA M是有序五(Q , Σ , δ , q 0 , F)。如果M在读取输入x后可能最终进入的每个可能状态都是属于F的状态,则M接受单词x Σ *。与 All-NFA 不同,如果这些可能状态中至少有一个是接受状态,则正则 NFA 会接受一个单词。证明 all-NFA 能够识别一类正则语言。

1.38 All-NFA M is an ordered 5 ( Q , Σ , δ , q 0 , F ). M accepts a word x Σ * if every possible state that M can enter after reading input x is a state in F . In contrast to All-NFA, an ordinary NFA accepts a word if at least one of these possible states is an accepting state. Prove that All-NFA recognizes the class of regular languages.

1.39 定理 1.54 所示的结构表明,每个 GNFA 等价于仅包含两个状态的 GNFA。我们可以证明 DFA 存在相反的现象。证明对于每个k > 1,都存在一种语言A k { 0 , 1 } *,使得它可以被包含k 个状态的 DFA 识别,但不能被仅包含k − 1 个状态的 DFA 识别。

1.39 The construction in Theorem 1.54 shows that every GNFA is equivalent to a GNFA with only two states. We can show that the opposite holds for DFAs. Prove that for every k > 1 there exists a language A k { 0 , 1 } * such that it is recognized by a DFA with k states but not by one with only k − 1 states.

1.40 回想一下,如果存在一个单词z使得xz = y,则x是单词y的前缀,并且如果另外x y ,则xy 的真前缀。在以下每一点中,我们定义了语言A上的某种操作。证明正则语言的类因该操作而封闭。

1.40 Recall that x is a prefix of a word y if there is a word z such that xz = y , and x is a proper prefix of y if, in addition, x y . In each of the following steps we define some operation on the language A . Show that the class of regular languages ​​is closed under this operation.

A a. NOPREFIX( A ) = { w A : 没有特定的前缀w属于语言A }。

A a.NOPREFIX ( A ) = { w A : no proper prefix w belongs to language A }.

b. NOEXTEND( A ) = { w A : w不是属于A 的任何单词的正确前缀}。

b. NOEXTEND( A ) = { w A : w is not a proper prefix of any word belonging to A }.

1.41 我们将语言A和 B完美重新洗牌称为语言

1.41 We will call the perfect shuffle of languages ​​A and  B the language

{ w : w = a 1 b 1 …a k b k,其中a 1a k Ab 1b k B对于每个a i , b i Σ }。

{ w : w = a 1 b 1 …a k b k , where a 1a k A and b 1b k B for every a i , b i Σ }.

证明正则语言的类在完美洗牌下是封闭的。

Prove that the class of regular languages ​​is closed under perfect shuffling.

1.42 语言A和 B的重新洗牌称为语言

1.42 The reshuffling of languages ​​A and  B is called the language

{ w : w = a 1 b 1 …a k b k,其中a 1a k Ab 1b k B对于每个a i , b i Σ * }。

{ w : w = a 1 b 1 …a k b k , where a 1a k A and b 1b k B for every a i , b i Σ * }.

证明正则语言的类由于重新洗牌而关闭。

Prove that the class of regular languages ​​is closed under reshuffling.

1.43A为任意语言。我们将 DROP-OUT( A ) 定义为一种包含所有单词的语言,这些单词可以通过从属于A 的单词中删除一个符号来获得。因此 DROP-OUT( A ) = { xz : xyz A,其中x , z Σ * , y Σ }。证明正则语言的类由于DROP-OUT操作而封闭。给出一个图形证明和一个更正式的构造证明,如定理 1.47 中所示。

1.43 Let A be an arbitrary language. We define DROP-OUT( A ) to be the language containing all words that can be obtained by removing one symbol from a word in A . So DROP-OUT( A ) = { xz : xyz A , where x , z Σ * , y Σ }. Prove that the class of regular languages ​​is closed under the DROP-OUT operation. Give both a proof by drawing and a more formal proof by construction, as in Theorem 1.47.

A 1.44BC是字母表上的语言Σ = { 0 , 1 }。我们定义

A 1.44 Let B and C be languages ​​over the alphabet Σ = { 0 , 1 }. We define

B 1 C = { w B:对于某些y C,单词w和 y包含相同数量的 1}。

B 1 C = { w B : for some y C the words w and  y contain equal numbers of ones}.

证明正则语言的类由于操作¬ 1而封闭。

Prove that the class of regular languages ​​is closed under the operation ¬ 1 .

*1.45A/B = { w : wx A对于某些x B }。证明如果A是正则语言,B是任意语言,则A/B是正则语言。

*1.45 Let A/B = { w : wx A for some x B }. Prove that if A is a regular language and B is any language, then A/B is a regular language.

1.46 证明下列语言不是正则语言。您可以使用泵引理和正则语言类的闭包来实现并集、交集和补集。

1.46 Prove that the following languages ​​are not regular. You can use the pumping lemma and the closure of the class of regular languages ​​under union, intersection, and complement.

{ 0 n 1 m 0 n : m , n 0}

a. { 0 n 1 m 0 n : m , n ≥ 0}

{ 0 m 1 n : mn }

A b. { 0 m 1 n : m n }

c. { w : w { 0 , 1 } *不是回文} 8

c. { w : w { 0 , 1 } * is not a palindrome} 8

* d { wtw : w , t { 0 , 1 } + }

* d . { wtw : w , t { 0 , 1 } + }

1.47Σ = { 1 , # } 并令

1.47 Let Σ = { 1 , # } and let

Y = { w : w = x 1 # x 2 # # x k对于k ≥ 0,每个x i 1 *x i x j对于i j }。

Y = { w : w = x 1 # x 2 # # x k for k ≥ 0, each x i 1 * and x i x j for i j }.

证明Y不是正则语言。

Prove that Y is not a regular language.

1.48Σ = { 0 , 1 } 并令

1.48 Let Σ = { 0 , 1 } and let

D = { w : w包含相同次数的子字0110 }。

D = { w : w contains an equal number of occurrences of the substrings 01 and 10 }.

这意味着101 D,因为101包含 1 次出现的01和 1 次10,但1010 D,因为1010包含两次出现的10和 1 次01。证明D是正则语言。

This means that 101 D , since 101 contains one occurrence of 01 and one occurrence of 10 , but 1010 D , since 1010 contains two occurrences of 10 and one occurrence of 01 . Show that D is a regular language.

1.49 a.B = { 1 k y : y { 0 , 1 } *y至少包含k个 1,k ≥ 1}。证明B是正则语言。

1.49 a. Let B = { 1 k y : y { 0 , 1 } * and y contains at least k 1s, k ≥ 1}. Prove that B is a regular language.

b.B = { 1 k y : y { 0 , 1 } *y最多包含k个,k ≥ 1}。证明B不是正则语言。

b. Let B = { 1 k y : y { 0 , 1 } * and y contains at most k 1s, k ≥ 1}. Prove that B is not a regular language.

A 1.50 阅读练习 1.24 中给出的有限传感器的非正式定义。如果输入和输出字母表为 { 0 , 1 },则 FST 不能为每个输入单词w返回w R 。

A 1.50 Read the informal definition of a finite-state transducer given in Exercise 1.24. Prove that no FST can return w for each input word w if the input and output alphabets are { 0 , 1 }.

1.51xy为单词,L为任意语言。如果存在单词z并且单词xzyz中的一个恰好属于L,则我们说xy通过 L 区分;否则,如果对于每个单词z我们得到xz L当且仅当yz L时,那么我们说xy无法通过L区分。如果xy无法通过L区分,我们将其写为x L y。证明L是等价关系。

1.51 Let x and y be words and L an arbitrary language. We say that x and y are distinguishable by L if there is a word z such that exactly one of the words xz and yz is in L ; otherwise, if for every word z we get xz L if and only if yz L , then we say that x and y are indistinguishable by L. If x and y are indistinguishable by L , we write this as x L y . Show that L is an equivalence relation.

A* 1.52 迈希尔-尼罗德定理。返回任务 1.51。设L是一种语言, X是一组单词。如果属于X的每两个不同单词都可以通过L区分则我们说X可以通过L成对区分。让我们将索引 L定义为可通过L成对区分的任何集合的最大元素数。 L索引可以是有限的或无限的。

A* 1.52 Myhill–Nerode Theorem . Return to Problem 1.51. Let L be a language and X be a set of words. We say that X is pairwise distinguishable by L if every two distinct words belonging to X are distinguishable by L . Let us define the index L as the maximum number of elements of any set that is pairwise distinguishable by L . The index L may be finite or infinite.

a. 证明如果L被k 个状态的 DFA 识别,则L的索引至多为k

a. Prove that if L is recognized by a k- state DFA, then the index of L is at most k .

b. 证明如果索引L是有限数k ,则它可以被包含k 个状态的 DFA 识别。

b. Prove that if the index L is a finite number k , then it is recognized by a DFA containing k states.

c. 得出L是正则的当且仅当它具有有限索引时。而且,这个索引是识别这种语言的最小DFA的大小。

c. Deduce that L is regular if and only if it has a finite index. Moreover, this index is the size of the smallest DFA that recognizes this language.

1.53Σ = { 0,1 , + , = } i

1.53 Let Σ = { 0 , 1 , + , = } and

ADD = { x = y + z : x , y , z是二进制整数,x是yz的和}。

ADD = { x = y + z : x , y , z are binary integers and x is the sum of y and z }.

表明ADD不是正则语言。

Show that ADD is not a regular language.

1.54 考虑语言F = { a i b j c k : i , j , k ≥ 0 且如果i = 1,则j = k }。

1.54 Consider the language F = { a i b j c k : i , j , k ≥ 0 and if i = 1, then j = k }.

a. 证明F不是正则语言。

a. Show that F is not a regular language.

b. 证明对于泵引理,语言 F 的行为就像它是正则的一样。换句话说,说明泵浦长度并证明F满足该p值的泵浦引理的三个条件。

(b) Show that with respect to the Pumping Lemma, the language F behaves as if it were regular. In other words, give the pumping length and demonstrate that F satisfies the three conditions of the Pumping Lemma for this value of p .

c. 解释为什么(a)(b)与泵引理不矛盾。

c. Explain why points (a) and (b) do not contradict the pumping lemma.

1.55 泵引理指出,每种正则语言都有泵长度p,这样该语言中的任何单词如果长度为p或更大,则可以被泵泵。如果p是语言A的泵浦长度,则任何长度p'p也是如此。语言A的最小泵浦长度是最小的p,即A的泵浦长度。例如,如果A = 01 *,则最小膨胀长度为 2。原因是单词s = 0属于A,长度为 1,但s不能膨胀;而A中长度为 2 或以上的每个单词都包含 1,因此可以通过将其除以x = 0y = 1z来泵送该单词的余数。提供以下每种语言的最小泵送长度,并解释您的答案。

1.55 The pumping lemma states that every regular language has a pumping length p such that every word of the language can be pumped if it has length p or greater. If p is a pumping length for language A , then so is any length p'p . The minimal pumping length for language A is the smallest p that is a pumping length of A . If, for example, A = 01 * , the minimal pumping length is 2. The reason is that the word s = 0 belongs to A and has length 1, but s cannot be pumped; on the other hand, every word in A of length 2 or greater contains a 1 and thus can be pumped by partitioning it so that x = 0 , y = 1 , and z is the remainder of the word. Give the minimal pumping length for each of the following languages, giving an explanation of your answer.

0001 *

A a. 0001 *

0 * 1 *

A b. 0 * 1 *

c. 001 0 * 1 *

c. 001 0 * 1 *

0 * 1 + 0 + 1 * 10 * 1

And d. 0 * 1 + 0 + 1 * 10 * 1

e. ( 01 ) *

e. ( 01 ) *

f

f. ε

1 * 01 * 01 *

g. 1 * 01 * 01 *

10 ( 11 * 0 ) * 0

h. 10 ( 11 * 0 ) * 0

一、 1011

and 1011

j

j. Σ *

* 1.56 如果A是一些自然数的集合, k是大于 1 的自然数,则令

* 1.56 If A is a set of some natural numbers and k is a natural number greater than 1, let

B k ( A ) = { w : w是A中某个数以k为基数的表示}。

B k ( A ) = { w : w is the base k representation of some number in A }.

在这种情况下,我们不允许在数字表示中使用前导零。例如,B 2 ({ 3 , 5 }) = { 11 , 101 } 且B 3 ({ 3 , 5 }) = { 10 , 12 }。给出一个集合A的示例,其中B 2 ( A ) 是正则语言,但B 3 ( A ) 不是正则语言。证明例子的正确性。

In this case we do not allow leading zeros in the representation of the number. For example, B 2 ({ 3 , 5 }) = { 11 , 101 }, and B 3 ({ 3 , 5 }) = { 10 , 12 }. Give an example of a set A for which B 2 ( A ) is regular but B 3 ( A ) is not regular. Prove the correctness of the example.

* 1.57A为任何语言;令A A Σ为属于A 的所有前半字的集合,使得

* 1.57 Let A be any language; let A A Σ be the set of all first half-words belonging to A , such that

A A = { x : 对于某些y , | x | = | y |且xy A }。

A A = { x : for some y , | x | = | y | and xy A }.

证明如果A是正则,则A A也是正则。

Prove that if A is regular, then A A is also regular.

* 1.58A为任何语言;设A B−B为A中所有单词的集合,去掉中间三分之一,即

* 1.58 Let A be any language; let A B−B be the set of all words in A with the middle third removed, that is,

A B−B = { xz:对于某些y, | x | = | y | = ||且xyz A }。

A B−B = { xz : for some y , | x | = | y | = | z | and xyz A }.

证明如果A是正则语言,则A B−B不必是正则语言。

Prove that if A is a regular language, A B−B need not be regular.

* 1.59M = ( Q , Σ , δ , q 0 , F ) 为 DFA, h为M的状态,称为“home”。 Mh同步序列是单词s Σ *,其中对于每个q Q δ ( q , s ) = h 。 [这里我们将函数δ的定义扩展到单词中,使得δ ( q , s ) 等于M从状态q开始并读取输入单词s时结束的状态。] 我们说M是可同步的如果它包含某个状态h的同步字符串。证明如果M一个k态可同步DFA,那么它有一个长度至多为k 3的同步序列。这个估计可以改进吗?

* 1.59 Let M = ( Q , Σ , δ , q 0 , F ) be a DFA and let h be a state of M called the "home" state. The synchronizing sequence for M and h is a word s Σ * , where δ ( q , s ) = h for all q Q . [Here we extend the definition of the function δ to words, so that δ ( q , s ) is equal to the state that M ends up in when it starts in state q and reads input word s .] We say that M is synchronizable if it contains a synchronizing sequence for some state h . Prove that if M is a k -state synchronizable DFA, then it has a synchronizing sequence of length at most k 3 . Can this estimate be improved?

1.60Σ = { a , b }。对于每个k ≥ 1,令C k是由所有在从右端算起的第 k 个位置包含a 的单词组成的语言。换句话说,C k = Σ * a Σ k -1。描述一个识别 C 语言的k +1 状态 NFA 作为状态图又作为形式描述。

1.60 Let Σ = { a , b }. For all k ≥ 1, let C k be the language of all words containing a in exactly the kth position from the right end. In other words, C k = Σ * a Σ k −1 . Describe an NFA with k + 1 states that recognizes the language C k , both as a state diagram and as a formal description.

1.61 考虑问题 1.60 中定义的C k语言。证明对于每个k,状态少于 2 k 的DFA无法识别C k

1.61 Consider the languages ​​C k defined in Problem 1.60. Prove that for each k no DFA with fewer than 2 k states can recognize C k .

1.62Σ = { a , b }。对于任何k ≥ 1,令D k是一种由最后k 个符号中至少包含一个a 的所有单词组成的语言。换句话说,D k = Σ * a ( Σ ε ) k -1。描述一个最多包含k +1 个状态的 DFA,该状态识别D k,既作为状态图又作为形式描述。

1.62 Let Σ = { a , b }. For each k ≥ 1, let D k be the language of all words that contain at least one a among the last k symbols. In other words, D k = Σ * a ( Σ ε ) k −1 . Describe a DFA with at most k +1 states that recognizes D k as both a state diagram and a formal description.

* 1.63 a.A为无限正则语言。证明A可以分为两个无限的、不相交的正则子集。

* 1.63 a. Let A be an infinite regular language. Prove that A can be divided into two infinite, disjoint regular subsets.

b.BD是两种语言。如果B D并且D包含无限多个不属于B 的单词,我们将写成B D。证明如果BD是两种正则语言且B D,我们可以找到正则语言C使得B C D。

b. Let B and D be two languages. We write B D if B D and D contains infinitely many words that are not members of B . Show that if B and D are two regular languages, where B D , we can find a regular language C such that B C D .

1.64N为包含k 个状态的 NFA ,其识别某种语言A

1.64 Let N be an NFA containing k states that recognizes some language A .

a. 证明如果A非空,则A最多包含一个长度为k的单词。

a. Prove that if A is nonempty, then A contains a word of length at most k .

*b。 通过示例表明,如果我们将A都替换为A ,则(a)点不一定为真。

*b. Show with an example that point (a) does not have to be true if we replace both A in it with A .

c. 证明如果A非空,则A最多包含一个长度为2k的单词。

c. Prove that if A is nonempty, then A contains a word of length at most 2k .

*d。表明(c) 中给出的限制几乎是严格的;换句话说,对于每个k,显示一个识别语言A k 的NFA ,其中A k是非空的,并且属于A k 的最短单词的长度相对于k呈指数增长。尝试尽可能接近(c)中的极限。

*d. Show that the constraint given in (c) is almost strict; in other words, for each k show an NFA that recognizes a language A k , where A k is nonempty and the shortest words of A k have length exponential in k . Try to get as close to the constraint in (c) as possible.

* 1.65 证明对于每个n > 0 都存在一种语言B n使得

* 1.65 Prove that for every n > 0 there exists a language B n such that

a. B n由包含n 个状态的 NFA 识别,

a. B n is recognizable by an NFA containing n states,

b. 如果B n = A 1 A k,其中A是正则语言,则A中至少一个需要包含指数多个状态的 DFA。

b. If B n = A 1 A k , where A and are regular languages, then at least one of these A and requires a DFA containing exponentially many states.

1.66 同态是一个函数f : ΣΓ *从一个字母表到另一个字母表上的一组单词。我们可以通过定义f ( w ) = f ( w 1 ) f ( w 2 )… f ( w n ) 来扩展f对单词进行操作,其中w = w 1 w 2 …w n且每个w iΣ。我们可以通过为任何语言A定义f ( A ) = { f ( w ) : w A } 来进一步扩展f来处理语言。

1.66 A homomorphism is a function f : ΣΓ * from one alphabet into the set of words over another alphabet. We can extend f to act on words by defining f ( w ) = f ( w 1 ) f ( w 2 )… f ( w n ), where w = w 1 w 2 …w n and each w i Σ . We can further extend f to act on languages ​​by defining f ( A ) = { f ( w ) : w A }, for any language A .

a. 通过形式化构造证明正则语言的类由于同态而封闭。换句话说,给定一个识别B的 DFA M和一个同态f,构造一个识别f ( B )的有限自动机M' 。分析构造的机器M'。是否在所有情况下都是 DFA?

a. Show by formal construction that the class of regular languages ​​is closed under homomorphism. In other words, given a DFA M recognizing B and a homomorphism f , construct a finite automaton M' that recognizes f ( B ). Analyze the constructed automaton M' . Will it be a DFA in each case?

b. 举例说明非正则语言的类由于同态而不是封闭的。

b. Show by an example that the class of irregular languages ​​is not closed under homomorphism.

*1.67 令语言A的旋转闭包为RC ( A ) = { yx : xy A }。

*1.67 Let the rotational closure of A be RC ( A ) = { yx : xy A }.

a.证明对于任何语言 A RC ( A ) = RC ( RC ( A ) ) 成立。

a. Show that for any language A RC ( A ) = RC ( RC ( A )).

b. 证明正则语言的类由于旋转闭包而被封闭。

b. Show that the class of regular languages ​​is closed under rotational closure.

* 1.68 在传统的洗牌方法中,一副牌被随机分成两部分,然后以相反的顺序折叠。在一种更高级的转移中,称为“斯卡恩转移”甲板被分为三部分,当甲板组装时,中间的部分被放置在顶部。我们将使用斯卡恩翻译作为一些舌头手术的灵感。对于语言A,令CUT ( A ) = { yxz : xyz A }。

* 1.68 In the traditional method of cutting a deck of cards, it is randomly divided into two pieces, which are then reassembled in reverse order. In a more advanced cut, called the Scarne cut , the deck is divided into three pieces and the middle piece is placed on top when the deck is reassembled. We will use Scarne 's cut as inspiration for a certain operation on languages. For language A , let CUT ( A ) = { yxz : xyz A }.

a. 显示语言B,其中CUT ( B ) CUT ( CUT ( B ))。

a. Show language B for which CUT ( B ) CUT ( CUT ( B )).

b. 证明正则语言类在CUT下是封闭的。

b. Prove that the class of regular languages ​​is closed under CUT .

1.69Σ = { 0 , 1 }。设WW k = { ww : w Σ *w的长度为k }。

1.69 Let Σ = { 0 , 1 }. Let WW k = { ww : w Σ * and w has length k }.

a. 证明对于任意k,状态数少于 2 k 的DFA无法识别WW k

a. Prove that for any k, no DFA with less than 2 k states can recognize WW k .

b.描述WW k 的更小的 NFA ,即WW k的补集。

b. Describe a much smaller NFA for WW k , the complement of WW k .

1.70我们将语言A和 B的避免 操作定义为

1.70 We define the avoids operation for languages ​​A and  B as

A 避免 B = { w : w A并且 w不包含B的任何单词作为子词}。

A avoids B = { w : w A and  w does not contain any word from B as a subword}.

证明正则语言的类由于避免操作而封闭。

Prove that the class of regular languages ​​is closed under the avoids operation .

1.71Σ = { 0 , 1 }。

1.71 Let Σ = { 0 , 1 }.

a.A = { 0 k u 0 k : k ≥ 1 且u Σ * }。证明A是正则语言。

a. Let A = { 0 k u 0 k : k ≥ 1 and u Σ * }. Prove that A is a regular language.

b.B = { 0 k 1 u 0 k : k ≥ 1 且u Σ * }。证明B不是正则语言。

b. Let B = { 0 k 1 u 0 k : k ≥ 1 and u Σ * }. Prove that B is not a regular language.

1.72M 1M 2分别为包含k 1k 2状态的两个DFA,并令U = L ( M 1 ) L ( M 2 )。

1.72 Let M 1 and M 2 be two DFAs that contain k 1 and k 2 states, respectively, and let U = L ( M 1 ) L ( M 2 ).

a. 证明如果U Ø,则U包含序列s使得 | s | < 最大值 ( k 1 , k 2 )。

a. Prove that if U Ø , then U contains some sequence s such that | s | < max( k 1 , k 2 ).

b. 证明如果U Σ *,则U不包含某些单词s使得 | s | < k 1 k 2

b. Prove that if U Σ * , then U does not contain some word s such that | s | < k 1 k 2 .

1.73Σ = { 0 , 1 , # }。令C = { x # x R # x| x Î { 0 , 1 }*}。证明C是 CFL

1.73 Let Σ = { 0 , 1 , # }. Let C = { x # x R # x| x Î { 0 , 1 }*}. Show that C is a CFL

精选解决方案

Selected solutions

1.1 对于M 1(a) q 1(b) { q 2 };(c) q 1q 2q 3q 1q 1(d)否;(e)

1.1 For M 1 : (a) q 1 ; (b) { q 2 }; (c) q 1 , q 2 , q 3 , q 1 , q 1 ; (d) No; (e) No

对于M 2(a) q 1(b) { q 1 , q 4 }; (c) q 1q 1q 1q 2q 4(d)是;(e)

For M 2 : (a) q 1 ; (b) { q 1 , q 4 }; (c) q 1 , q 1 , q 1 , q 2 , q 4 ; (d) Yes; (e) No

1.2 M 1 = ({ q 1 , q 2 , q 3 }, { a , b }, δ 1 , q 1 , { q 2 })。

1.2 M 1 = ({ q 1 , q 2 , q 3 }, { a , b }, δ 1 , q 1 , { q 2 }).

M2 = ({ q 1 , q 2 , q 3 , q 4 }, { a , b }, δ 2 , q 1 , { q 1 , q 4 })。

M2 = ({ q 1 , q 2 , q 3 , q 4 }, { a , b }, δ 2 , q 1 , { q 1 , q 4 }).

过渡函数是

The transition functions are

δ1

δ 1

and

b

δ2

δ 2

and

b

q 1

q1

q 2

q2

q 1

q1

q 1

q1

q 1

q1

q 2

q2

q 2

q2

q 3

q3

q 3

q3

q 2

q2

q 3

q3

q 4

q4

q 3

q3

q 2

q2

q 1

q1

q 3

q3

q 2

q2

q 1

q1

q 4

q4

q 3

q3

q 4

q4

1.4 (b)下面显示的是两种语言的 DFA { w : w恰好包含两个a } 和 { w : w至少包含两个b }。

1.4 (b) Below is a DFA for two languages ​​{ w : w contains exactly two a's } and { w : w contains at least two b 's }.

使用交集结构将它们组合起来可得到以下 DFA。

Combining them using the intersection construction gives the DFA below.

尽管该任务不要求简化此 DFA,但可以组合某些状态以给出以下 DFA。

Although the problem does not require simplifying this DFA, certain states can be combined, resulting in the following DFA.

(d)下面显示的是两种语言的 DFA { w : w包含偶数个a } 和 { w : w中的 每个a后面至少有一个b }。

(d) Below are DFAs for two languages ​​{ w : w contains an even number of a } and { w : every a in  w is followed by at least one b }.

使用交集结构将它们组合起来可得到以下 DFA。

Combining them using the intersection construction gives the DFA below.

尽管该任务不要求简化此 DFA,但可以组合某些状态以给出以下 DFA。

Although the problem does not require simplifying this DFA, certain states can be combined, resulting in the following DFA.

1.5 (a)左侧所示的 DFA 识别语言 { w : w contains ab }。右 DFA 识别其补码 { w : w不包含ab }。

1.5 (a) The DFA shown on the left recognizes the language { w : w contains ab }. The right DFA recognizes its complement, { w : w does not contain ab }.

(b)以下 DFA 识别语言 { w : w contains baba }。

(b) The following DFA recognizes the language { w : w contains baba }.

该 DFA 识别语言 { w : w不包含baba }。

This DFA recognizes the language { w : w does not contain baba }.

1.7 (a)(f)

1.7 (a) (f)

1.11N = ( Q , Σ , δ , q 0 , F ) 为任意 NFA。我们用单个接受状态构建 NFA N' ,该接受状态将识别与N相同的语言。非正式地,N'与N相同,除了它包含新的接受状态qaccept和从与接受N的状态相对应的状态引导到新状态的ε-转换。 q接受状态没有传出转换。更正式地说,N' = ( Q { q Accept }, Σ , δ' , q 0 , { q Accept }),其中对于每个q Qa Σ ε

1.11 Let N = ( Q , Σ , δ , q 0 , F ) be an arbitrary NFA. We construct an NFA N' with a single accepting state that recognizes the same language as N . Informally, N' is identical to N except that it contains a new accepting state q accept and ε -transitions leading from states corresponding to the accepting states of N to the new state. The state q accept has no outgoing transitions. More formally, N' = ( Q { q accept }, Σ , δ' , q 0 , { q accept }), where for every q Q and a Σ ε

δ' ( q Accept , a ) = Ø对于所有a Σ ε

and δ' ( q accept , a ) = Ø for every a Σ ε .

1.23 我们“当且仅当”证明两个方向。

1.23 We prove both directions "if and only if".

( ) 我们假设B = B +并证明BB B

( ) We assume that B = B + and we will show that then BB B .

对于每种语言BB B +都成立,因此如果B = B +,则BB B

For every language, BB B + holds , so if B = B + , then BB B .

( Ü ) 我们假设BB B并证明B = B +

( Ü ) We assume that BB B and we will show that then B = B + .

因此,对于任何语言B B +,我们只需要证明B + B。如果w B +,则w = x 1 x 2 …x k,其中每个x i Bk ≥ 1。由于x 1x 2 BBB B,我们得到x 1 x 2 B。类似地,由于x 1 x 2属于Bx 3属于B ,所以我们得到x 1 x 2 x 3 B。继续这样,我们得到x 1 x 2 …x k B。因此w B,因此我们可以得出B + B的结论。

For any language B B + , therefore we need only show that B + B . If w B + , then w = x 1 x 2 …x k , where every x i B and k ≥ 1. Since x 1 , x 2 B and BB B , we get x 1 x 2 B . Analogously, since x 1 x 2 is a member of B and x 3 is a member of B , we get x 1 x 2 x 3 B . Continuing in this way, we get x 1 x 2 …x k B . Hence w B , and we can conclude that B + B .

第二个推理可以正式写为以下归纳证明。

This second reasoning can be written formally as the following proof by induction.

我们假设BB B

We assume that BB B .

论文:对于每个k ≥ 1,如果x 1 , …, x k B,则x 1 …x k B

Thesis : For every k ≥ 1, if x 1 , …, x k B , then x 1 …x k B .

基本步骤:证明k = 1。这个陈述显然是正确的。

Basic step : Proof for k = 1. This statement is obviously true.

归纳步骤:对于每个k ≥ 1,我们假设该命题对于k成立,并且我们证明它对于k + 1 成立。

Inductive step : For each k ≥ 1, we assume that the theorem is true for k , and prove that it is true for k + 1.

如果x 1 , …, x k , x k +1 B,则基于归纳假设x 1 …x k B。因此,x 1 …x k x k +1 BB,但BB B,因此x 1 …x k x k +1 B。这样就完成了归纳步骤和论文的证明。该论文意味着如果BB B,则B + B

If x 1 , …, x k , x k +1 B , then by the inductive assumption x 1 …x k B . Hence x 1 …x k x k +1 BB , but BB B , therefore x 1 …x k x k +1 B . This completes the proof of the inductive step and the thesis. It follows from the thesis that if BB B , then B + B .

1.29 (a)我们假设语言A 1 = { 0 n 1 n 2 n : n ≥ 0} 是正则语言。令p为由泵浦引理得出的泵浦长度。我们选择单词0 p 1 p 2 p作为s。由于s是A 1的元素并且s比p长,泵引理确保s可以分为三部分,s = xyz,其中对于每个i ≥ 0,单词xyz属于A 1。让我们考虑两种可能性:

1.29 (a) Assume that the language A 1 = { 0 n 1 n 2 n : n ≥ 0} is regular. Let p be the pumping length that follows from the Pumping Lemma. We choose s to be the word 0 p 1 p 2 p . Since s is an element of A 1 and s is longer than p , the Pumping Lemma ensures that s can be partitioned into three parts, s = xyz , where for each i ≥ 0 the word xy and z belong to A 1 . Consider two possibilities:

1. 单词y由全0、全1或全2组成。在这些情况下,单词xyyz将不具有相同数量的数字012。因此,xyyz不属于语言A 1,这意味着矛盾。

1. The word y consists of all 0s , all 1s , or all 2s . In these cases the word xyyz will not have an equal number of digits 0 , 1 , and 2. Thus xyyz does not belong to the language A 1 , which means a contradiction.

2. 单词y包含不止一种类型的符号。在这种情况下,xyyz将包含乱序的012 。因此,xyyz不属于语言A 1,这是矛盾的。

2. The word y contains more than one kind of symbol. In this case xyyz will contain 0 , 1 or 2 out of order. Thus xyyz does not belong to the language A 1 , a contradiction.

在每种情况下我们都得到了一个矛盾。因此,A 1不是正则语言。

In each case we have obtained a contradiction. Therefore A 1 is not a regular language.

(c)假设A 3 = { a 2 n : n ≥ 0} 是正则的。令p为由泵浦引理得出的泵浦长度。我们选择a 2 p作为s词。由于s是A 3的元素并且s比p长,泵引理确保s可以分为三部分,s = xyz,其中对于每个i ≥ 0,单词xyz属于A 3

(c) Suppose A 3 = { a 2 n : n ≥ 0} is regular. Let p be the pumping length that follows from the Pumping Lemma. We choose as s the word a 2 p . Since s is an element of A 3 and s is longer than p , the Pumping Lemma ensures that s can be partitioned into three parts, s = xyz , where for each i ≥ 0 the word xy and z belong to A 3 .

引理的第三个条件说 | XY | ≤ p。此外,p < 2 p且 | y | < 2 p。因此| xyyz | = | XYZ |+| y | < 2p + 2p = 2p +1第二个条件要求 | y | > 0,因此 2 p < | xyyz | < 2p +1。因此xyyz的长度不能是 2 的幂。因此xyyz不是A 3的元素,这是一个矛盾。因此,A 3不是正则语言。

The third condition of the lemma says that | xy | ≤ p . Additionally , p < 2 p and therefore | y | < 2 p . Hence, | xyyz | = | xyz |+| y | < 2 p +2 p = 2 p +1 . The second condition requires that | y | > 0, hence 2 p < | xyyz | < 2 p +1 . The length of xyyz cannot therefore be a power of 2. Hence xyyz is not an element of A 3 , which is a contradiction. Hence, A 3 is not a regular language.

1.40 (a)M = ( Q , Σ , δ , q 0 , F ) 为识别A的 DFA ,其中A是某种正则语言。我们构造M' = ( Q' , Σ , δ' , q 0 ' , F' ) 来识别NOPREFIX语言(A),如下所示:

1.40 (a) Let M = ( Q , Σ , δ , q 0 , F ) be a DFA recognizing A , where A is some regular language. We construct M' = ( Q' , Σ , δ' , q 0 ' , F' ) recognizing the NOPREFIX language (A) as follows:

1. Q' = Q

1. Q' = Q .

2. 对于r Q'a Σ,我们定义δ' ( r , a ) =

2. For r Q' and a Σ , we define δ' ( r , a ) =

3. q 0 ' = q 0

3. q 0 ' = q 0 .

4. F' = F

4. F' = F .

1.44M B = ( Q B , Σ , δ B , q B , F B ) 和M C = ( Q C , Σ , δ C , q C , F C ) 分别为识别语言BC的 DFA 。我们构造一个 NFA M = ( Q , Σ , δ , q 0 , F ) 来识别B Ø 1 C如下。为了确定输入数据是否属于B 1 C,机器M检查w B并并行非确定性地猜测单词y ,该单词包含与w中相同数量的 1并检查y C 。

1.44 Let M B = ( Q B , Σ , δ B , q B , F B ) and M C = ( Q C , Σ , δ C , q C , F C ) be DFAs recognizing languages ​​B and C , respectively . We construct an NFA M = ( Q , Σ , δ , q 0 , F ) recognizing B ¬ 1 C as follows. To determine whether the input belongs to B ¬ 1 C , the machine M checks that w B and in parallel nondeterministically guesses a word y that contains the same number of 1s as contained in w and checks that y C .

1. Q = Q B × Q C

1. Q = QB × QC .

2. 对于 ( q , r ) ε Qa ε Σ ε,我们定义

2. For ( q , r ) Q and a Σ ε , we define

3. q 0 = ( q B , q C )。

3. q 0 = ( q B , q C ).

4. F = F B × F C

4. F = F B × F C .

1.46 (b)B = { 0 m 1 n : m n }。我们注意到B 0 * 1 * = { 0 k 1 k : k ≥ 0}。如果B是正则语言,那么B就是正则语言,这同样适用于B 0 * 1 *。然而,我们已经知道 { 0 k 1 k : k ≥ 0} 不是正则语言,因此B不可能是正则语言。

1.46 (b) Let B = { 0 m 1 n : m n }. We note that B 0 * 1 * = { 0 k 1 k : k ≥ 0}. If B were a regular language, then B would be regular and the same would be true for B 0 * 1 * . However, we already know that { 0 k 1 k : k ≥ 0} is not a regular language, so B cannot be regular.

或者,我们可以直接使用泵引理来证明B的非正则性,尽管这更困难。假设B = { 0 m 1 n : ¹  n } 是正则语言。令p为由泵浦引理得出的泵浦长度。请注意,p!可被 1 到p 的所有整数整除,其中p ! = p ( p − 1)( p − 2)…1。字s = 0 p 1 p + p ! ε B i | s | ≥ p。因此,根据泵送引理,s可以表示为xyz,其中x = 0 ay = 0 bz = 0 c 1 p + p,其中b ≥ 1 且a + b + c = p。令s'为单词xy+1 z,其中i = p !/ b。那么y i = 0 p,所以y i +1 = 0 b + p类似地s' = 0 a + b + c + p1p + p。这给出s' = 0 p + p1 p + p ! ∉B——矛盾

Alternatively, we can prove the irregularity of B directly using the Pumping Lemma, although this procedure is more difficult. Suppose B = { 0 m 1 n : ¹  n } is a regular language. Let p be the pumping length, which follows from the Pumping Lemma. Note that p ! is divisible by all integers from 1 to p , where p ! = p ( p − 1)( p − 2)…1. The word s = 0 p 1 p + p ! B and | s | ≥ p . Therefore, by the Pumping Lemma, s can be represented as xyz , where x = 0 a , y = 0 b , and z = 0 c 1 p + p ! , where b ≥ 1 and a + b + c = p . Let s' be a word xy i +1 z , where i = p !/ b . Then y i = 0 p ! , therefore y i +1 = 0 b + p ! and analogously s' = 0 a + b + c + p ! 1 p + p ! . This gives s' = 0 p + p ! 1 p + p ! B – a contradiction.

1.50 相反,假设某个 FST T对于输入w返回w R。考虑输入字0001。对于输入00 T必须返回00,对于输入01 T必须返回10。在这两种情况下,第一个输入位都是0,但第一个输出位不同。这种类型的行为对于 FST 来说是不可能的,因为它在读取第二个输入符号之前创建第一个输出符号。因此,这样的FST不可能存在。

1.50 Suppose, on the contrary, that a certain FST T returns w R for an input w . Consider the input words 00 and 01 . For an input of 00, T must return 00 , and for an input of 01 , T must return 10 . In both cases, the first input bit is 0 , but the first output bits are different. Such an operation is impossible for an FST, since it produces its first output symbol before reading the second input symbol. Hence, such an FST cannot exist.

1.52 (a)我们将间接证明这个定理。令M为识别L 的k状态 DFA 。与定理相反,我们假设L的索引大于k。这意味着某些具有超过k 个元素的X可以通过L成对区分。由于M具有k 个状态,鸽笼规则意味着X包含两个不同的词xy,使得δ ( q 0 , x ) = δ ( q 0 , y ) 。回想一下,δ ( q 0 , x ) 是M在初始状态q 0开始并读取输入字x后所处的状态。那么对于任何单词z Σ *δ ( q 0 , xz ) = δ ( q 0 , yz ) 。因此,要么xzyz都属于L,要么都不属于L。然而,那么xy不能被L区分,这与X可以被L成对区分的假设相矛盾。

1.52 (a) We prove this theorem indirectly. Let M be a k -state DFA that recognizes L . Suppose, conversely, that L has index greater than k . This means that some X with more than k elements is pairwise distinguishable by L . Since M has k states, the pigeonhole principle implies that X contains two distinct words x and y , such that δ ( q 0 , x ) = δ ( q 0 , y ). Recall that δ ( q 0 , x ) is the state that M is in after starting in the initial state q 0 and reading the input word x . Then for any word z Σ * , δ ( q 0 , xz ) = δ ( q 0 , yz ). Thus, either both xz and yz belong to L , or neither of them belongs to L . However, then x and y are not discriminable by L , which contradicts the assumption that X is pairwise discriminable by L .

(b)X = { s 1 , …, s k } 为可通过L区分的成对集合。我们将构造一个具有k 个状态的 DFA M = ( Q , Σ , δ , q 0 , F ) ,识别L。令Q = { q 1 , …, q k };我们将δ ( q i , a ) 定义为q j,其中s j == L s i a(关系== L在问题 1.51 中定义)。请注意,对于某些s jX , s j == L s i a;否则,集合X s i a将具有k + 1 个元素,并且可以通过L成对区分,这与L具有索引k的假设相矛盾。令F = { q i : s iL }。令初始状态q 0q i ,使得s iL εM的构造使得对于任何状态q i, { s : δ ( q 0 , s ) = q i } = { s : s L s i }。因此,M识别语言L。

(b) Let X = { s 1 , …, s k } be a pairwise distinguishable set by L . We construct a DFA M = ( Q , Σ , δ , q 0 , F ) with k states, recognizing L . Let Q = { q 1 , …, q k }; we define δ ( q i , a ) to be q j , where s j L s i a (the relation L was defined in Problem 1.51). Note that s j L s i a for some s j X ; otherwise the set X s i a would have k + 1 elements and would be pairwise distinguishable by L , which would contradict the assumption that L has index k . Let F = { q i : s i L }. Let the initial state q 0 be such q i that s i L ε . M is constructed in such a way that for any state q i , { s : δ ( q 0 , s ) = q i } = { s : s L s i }. Hence M recognizes the language L .

(c)假设L是正则语言,令k为识别L的DFA的状态数。然后,基于点(a),L的索引至多等于k。相反,如果L具有索引k,则基于点 ( b ),它可以被k 个状态的 DFA 识别,因此是正则的。为了表明索引L是接受它的最小 DFA 的量值,假设索引L恰好是k。那么,由 ( b ) 可知,存在一个接受L 的k状态 DFA 。这是最小的此类 DFA,因为如果存在更小的 DFA,我们可以从 (a) 证明索引L小于k

(c) Suppose L is a regular language and let k be the number of states of a DFA that recognizes L . Then by (a) L has index at most k . Conversely, if L has index k , then by ( b ) it is recognized by a k - state DFA and is therefore regular. To show that the index of L is the size of the smallest DFA that accepts it, suppose that the index of L is exactly k . Then by ( b ) there exists a k -state DFA that accepts L . This is the smallest such DFA, since if there were a smaller one, we could show by (a) that the index of L is less than k .

1.55 (a)最小泵长度为4。字000属于该语言但不能泵,因此3不是该语言的泵长度。如果s 的长度为 4 或更大,则它包含 1s。通过将单词s分为xyz,其中x000y是素数 1 ,以及其他所有内容,我们满足泵引理的所有三个条件。

1.55 (a) The minimum pumping length is 4. The word 000 belongs to the language but cannot be pumped, so 3 is not a pumping length for that language. If s has length 4 or greater, then it contains ones. By splitting the word s into xyz , where x is 000 , y is the first one, and everything else, we satisfy all three conditions of the Pumping Lemma.

(b)最小泵送长度为1。泵送长度不能为0,因为单词ε属于该语言但不能被泵送。该语言中的任何非空单词都可以拆分为xyz,其中xyz分别是ε、第一个字符和余数。该除法满足引理的三个条件。

(b) The minimal pumping length is 1. The pumping length cannot be 0, since the word ε belongs to the language but cannot be pumped. Every nonempty word in the language can be partitioned into xyz , where x , y , and z are ε , the first character, and the remainder, respectively . This partitioning satisfies the three conditions of the lemma.

(d)最小泵长度为 3。泵长度不能为 2,因为单词11属于该语言并且不能被泵。令s为语言中长度至少为 3 的单词。如果s由0 * 1 + 0 + 1 *生成,并且从011开始,那么我们可以写s = xyz,其中x = εy是第一个符号,z是s的剩余部分。如果s由0 * 1 + 0 + 1 *生成并从10开始,那么我们写s = xyz,其中x = 10y是下一个符号,余数s。以这种方式分裂s表明它可以被泵送。如果s是由10 * 1生成的,那么我们可以将其写为xyz,其中x = 1y = 0z是s的余数。该部门还提供泵送s的能力。

(d) The minimum pumping length is 3. The pumping length cannot be 2, since word 11 belongs to the language and cannot be pumped. Let s be a word from the language of length at least 3. If s is generated by 0 * 1 + 0 + 1 * and starts with either 0 or 11 , then we can write s = xyz , where x = ε , y is the first symbol, and z is the remainder of s . If s is generated by 0 * 1 + 0 + 1 * and starts with 10 , then we write s = xyz , where x = 10 , y is the next symbol, and z is the remainder of s . Partitioning s in this way shows that it can be pumped. If s is generated by 10 * 1 , then we can write it as xyz , where x = 1 , y = 0 , and z is the remainder of s . This partitioning also provides the possibility of pumping s .

2

上下文无关语言

2

Context-free languages

在第一章中,我们介绍了两种不同但等效的描述语言的方法:有限自动机和正则表达式。我们已经证明,很多语言都可以这样描述,但是一些简单的语言比如{ 0 n 1 n : n ≥ 0}则不能。

In Chapter 1 we introduced two different but equivalent methods for describing languages: finite automata and regular expressions. We showed that many languages ​​can be described in this way, but some simple languages, such as { 0 n 1 n : n ≥ 0}, cannot.

在本章中,我们介绍上下文无关语法(CFG),这是一种更强大的描述语言的方法。此类语法可以描述具有递归结构的特定属性,这使得它们在各种应用中都很有用。

In this chapter, we introduce context -free grammars ( CFGs), a more powerful way of describing languages. Such grammars can describe special properties that have a recursive structure, which makes them useful in a variety of applications.

上下文无关语法最初用于人类(自然)语言的研究。理解名词动词介词等概念及其相应短语之间关系的一种方法涉及自然递归,因为名词短语可以出现在动词短语内部,反之亦然。上下文无关语法有助于组织和理解这些关系。

Context-free grammars were originally used in the study of human (natural) languages. One way to understand the relationships between concepts such as nouns , verbs , and prepositions and their corresponding phrases involves natural recursion, since noun phrases can appear inside verb phrases and vice versa. Context-free grammars help to organize and understand these relationships.

上下文无关语法的一个重要用途是编程语言的规范和编译。当有人试图学习一种语言的语法时,编程语言语法通常会作为参考。编程语言的编译器和解释器的设计者通常从获取该语言的语法开始。大多数编译器和解释器都包含一个称为解析器的组件,它在生成编译代码或解释执行之前提取程序的含义。当上下文无关语法可用时,有许多方法可以使解析器构建变得更容易。有些工具甚至可以根据语法自动生成解析器。

An important use of context-free grammars is in specifying and compiling programming languages. A programming language grammar often appears as a reference when someone is trying to learn the syntax of a language. Designers of programming language compilers and interpreters often start by obtaining the grammar of the language. Most compilers and interpreters include a component called a parser , which extracts the meaning of a program before generating compiled code or interpreted execution. There are many methodologies that facilitate the construction of a parser when a context-free grammar is available. Some tools can even automatically generate a parser from the grammar.

与上下文无关语法相关的语言称为上下文无关语言 CFL )。该集合包括所有正则语言和许多附加语言。在本章中,我们将提出上下文无关语法的正式定义,并研究上下文无关语言的属性。我们还将介绍堆叠自动机的概念,这是一类识别上下文无关语言的机器。基于堆栈的自动机很有用,因为它们提供了对上下文无关语法功能的额外见解。

The languages ​​that are related to context-free grammars are called context -free languages ​​( CFL ). This set includes all regular languages ​​and many additional languages. In this chapter, we provide a formal definition of context-free grammars and study the properties of context-free languages. We also introduce the notion of pushdown automata , a class of machines that recognize context-free languages. Pushdown automata are useful because they provide additional insight into the possibilities of context-free grammars.

2.1

上下文无关语法

2.1

Context-free grammars

下面是上下文无关语法的示例,我们将其称为G 1

Below is an example of a context-free grammar, which we will call G 1 .

A 0 A 1

A 0 A 1

A B

B #

B #

语法由一组产生式组成,也称为替换规则。每个产生式都采用单独的语法行的形式,由左侧的符号和右侧的单词组成,并用箭头分隔。左边的符号称为变量(或非终结符)。一个字由变量和其他称为终结符的符号组成。变量符号通常使用大写字母表示。终端类似于输入字母表,通常以小写字母、数字或特殊字符表示。一个变量被指定为初始变量。它通常发生在最高产量的左侧。例如,语法G 1包含三个产生式。G 1的变量是A和 B,其中A是初始变量。它的终端是01#

A grammar consists of a set of productions , also called substitution rules . Each production takes the form of a separate line in the grammar, consisting of a symbol on the left and a word on the right, separated by an arrow. The symbol on the left is called a variable (or nonterminal symbol ). The word consists of variables and other symbols called terminals . Variable symbols are often represented using uppercase letters. Terminals are analogous to the input alphabet and are usually represented by lowercase letters, digits, or special characters. One variable is designated as the initial variable . It usually appears to the left of the highest production. For example, the grammar G 1 contains three productions. The variables of G 1 are A and  B , with A being the initial variable. Its terminals are 0 , 1 , and # .

我们通过生成属于该语言的每个单词来使用语法来描述该语言,如下所示。

We use a grammar to describe a language by generating each word belonging to that language in the following way.

  1. 我们打印初始变量。除非另有明确说明,否则这是第一个产生式左侧的变量。
  2. We print the initial variable. This is the variable on the left of the first production, unless otherwise explicitly stated.
  3. 在书面文字中,我们找到一个变量以及以该变量开头的产生式。我们用这个产生式的右侧替换写入的变量。
  4. In the printed word we find a variable and a production that starts with that variable. We replace the printed variable with the right side of that production.
  5. 我们重复步骤 2,直到只剩下终端。
  6. Repeat step 2 until only terminals remain.

例如,语法G 1生成单词000#111。产生一个单词的替换序列称为派生G 1文法中单词000#111的推导为

For example, the grammar G 1 generates the word 000#111 . The sequence of substitutions leading to the word is called a derivation . The derivation of the word 000#111 in the grammar G 1 is

A⇒0A1⇒00A11⇒000A111⇒000B111⇒000 # 111 ​​​​

A 0A1 00A11 000A111 000B111 000#111.

相同的信息可以形象地表示为解剖树(推导树)。图 2.1 显示了解析树的示例。

The same information can be represented pictorially as a parse tree . An example of a parse tree is shown in Figure 2.1.

2.1语法G 1中单词000#111

的解析树

Figure 2.1.

The parse tree for the word 000#111 in grammar G 1

所有以这种方式派生的单词就构成了语法生成的语言G 1文法的语言写作L ( G 1 )。对G 1的语法进行一些实验表明L ( G 1 ) 是 { 0 n #1 n : n ≥ 0}。任何可以通过上下文无关语法生成的语言都称为上下文无关语言(CFL)。在编写上下文无关语法时,为了方便起见,我们会将左侧具有相同变量的多个产生式(例如A 0 A 1 和A B)缩短为一行,例如A 0 A 1 | B、使用符号“|”作为替代方案(“或”)。

All the words derived in this way form the language generated by the grammar . We write the language for grammar G 1 as L ( G 1 ). A little experimentation with grammar G 1 shows that L ( G 1 ) is { 0 n #1 n : n ≥ 0}. Any language that can be generated by some context-free grammar is called a context -free language (CFL). When writing context-free grammars, we will conveniently abbreviate multiple productions with the same variable on the left, such as A 0 A 1 and A B , into one line, for example A 0 A 1 | B , by using the symbol "|" as an alternative ("or").

下面是上下文无关语法的第二个示例,我们将其称为G2 描述英语语言的片段。

Below is a second example of a context-free grammar, which we call G 2 , describing a fragment of English.

句子 名词短语〉〈动词短语

SENTENCE NOUN-PHRASE 〉〈 VERB-PHRASE

名词短语 CMPLX-名词 | CMPLX-名词〉〈准备短语

NOUN-PHRASE CMPLX-NOUN | CMPLX-NOUN 〉〈 PREP-PHRASE

动词短语 CMPLX-动词 | CMPLX-动词〉〈准备短语

VERB-PHRASE CMPLX-VERB | CMPLX-VERB 〉〈 PREP-PHRASE

准备短语 准备〉 〈 CMPLX 名词

PREP-PHRASE PREP 〉〈 CMPLX-NOUN

CMPLX-名词 文章〉 〈名词

CMPLX-NOUN ARTICLE 〉〈 NOUN

CMPLX-动词 动词 | 动词〉〈名词短语

CMPLX-VERB VERB | VERB 〉〈 NOUN-PHRASE

文章 a |

ARTICLE a | the

名词 男孩|女孩|

NOUN boy | girl | flower

动词 触及|喜欢|看到

VERB touches | likes | sees

准备

PREP with

语法G 2包含 10 个变量(尖括号中大写的语法术语); 27个终端(标准英文字母加空格字符);和18部作品。属于L ( G 2 ) 的单词包括:

The grammar G 2 contains 10 variables (capitalized grammatical terms placed in angle brackets); 27 terminals (the standard English alphabet plus the space character); and 18 productions. Words belonging to L ( G 2 ) include:

一个男孩看到

a boy sees

男孩看到一朵

the boy sees a flower

一个有的女孩喜欢这个男孩

a girl with a flower likes the boy

这些单词中的每一个在G 2语法中都有一个派生。该列表中第一个单词的派生如下所示。

Each of these words has a derivation in the grammar G 2 . The derivation of the first word in this list is shown below.

句子 名词短语〉 〈动词短语

SENTENCE NOUN-PHRASE 〉〈 VERB-PHRASE

CMPLX-名词〉〈动词短语

CMPLX-NOUN 〉〈 VERB-PHRASE

冠词〉〈名词〉〈动词短语

ARTICLE 〉〈 NOUN 〉〈 VERB-PHRASE

名词〉〈动词短语

NOUN 〉〈 VERB-PHRASE

一个男孩 动词短语

a boy VERB-PHRASE

一个男孩 CMPLX-动词

a boy CMPLX-VERB

一个男孩 动词

a boy VERB

一个男孩看到

a boy sees

上下文无关语法的形式定义

Formal definition of context-free grammar

我们现在形式化上下文无关语法(CFG)的概念。

We now formalize the notion of a context-free grammar (CFG).

定义 2.2

Definition 2.2

上下文无关语法是一个有序四元组 ( V , Σ , R , S ),其中

A context-free grammar is an ordered quadruple ( V , Σ , R , S ), where

  1. V是一个有限集,称为变量集
  2. V is a finite set called the set of variables ,
  3. Σ是与V不相交的有限集,称为终结集
  4. Σ is a finite disjoint set from V , called the terminal set ,
  5. R是产生式的有限集合,每个产生式由一个变量和一个由变量和终结符组成的词组成,
  6. R is a finite set of productions , where each production consists of a variable and a word built from variables and terminals,
  7. S V是初始变量。
  8. S V is the initial variable.

如果uvw是由变量和终结符组成的单词,并且A w是语法的产生式,那么我们说从单词uAv 派生出 uwv,我们将其写作uAv uwv。我们说u 导出 v ,如果u = v或者存在一个序列u 1 , u 2 , …, u k对于k ≥ 0 ,我们将其写为u * v ,使得

If u , v , and w are words composed of variables and terminals, and A w is a production of the grammar, then we say that from the word uAv we derive uwv , which is written uAv uwv . We say that u derives v , which is written u * v , if u = v or if there is a sequence u 1 , u 2 , …, u k for k ≥ 0, such that

u u 1 u 2 u k v

u u 1 u 2 u k v .

语法的语言是 { w Σ * : S * w }。

The language for the grammar is { w Σ * : S * w }.

G 1语法中,我们有V = { A , B }, Σ = { 0 , 1 , # }, S = A,并且R是第 102 页所示的三个产生式的集合。在G 2语法中,

In grammar G 1 we have V = { A , B }, Σ = { 0 , 1 , # }, S = A , and R is the set of three productions presented on page 102. In grammar G 2 ,

V = { 句子名词短语动词短语预备短语CMPLX-名词CMPLX-动词文章名词〉动词准备},

V = { SENTENCE , NOUN-PHRASE , VERB-PHRASE , PREP-PHRASE , CMPLX-NOUN , CMPLX-VERB , ARTICLE , NOUN , VERB , PREP },

Σ = { a , b , c , …, z , “ ”}。 “ ”符号是每个单词( aboy等)后面不可见的空格,因此单词不会粘在一起。

a Σ = { a , b , c , …, z , " "}. The " " symbol is a space, placed invisibly after each word ( a , boy , etc.), so that the words do not stick together.

语法通常通过列出产生式本身来指定。我们将变量定义为出现在产生式左侧的符号,将终结符定义为剩余的符号。按照惯例,起始变量是第一个产生式左侧的变量。

A grammar is often specified by listing the productions themselves. We identify variables as those symbols that appear on the left-hand side of the production, and terminals as the remaining symbols. By convention, the initial variable is the variable on the left-hand side of the first production.

上下文无关语法的示例

Examples of context-free grammars

2.3

Example 2.3

考虑语法G 3 = ({ S }, { a , b }, R , S )。生产集R

Consider the grammar G 3 = ({ S }, { a , b }, R , S ). The set of productions R is

S a S b | SS | ε。

S a S b | SS | ε.

此语法生成诸如ababaaabbbaababb等单词。如果我们将a视为左括号“(”,b视为右括号“)”,就会更容易理解这种语言是什么。这样看来,L ( G 3 ) 是所有正确间隔的括号字符串的语言。你可以看到产生式的右边可以是一个空词ε。

This grammar generates words like abab , aaabbb , and aababb . It will be easier to understand what this language is if we think of a as a left parenthesis "(" and b as a right parenthesis ")". Viewed in this way, L ( G 3 ) is the language of all sequences of correctly spaced parenthesis. It can be seen that the right-hand side of the production can be the empty word ε.

2.4

Example 2.4

考虑语法G 4 = ( V , Σ , R , EXPR )。

Consider the grammar G 4 = ( V , Σ , R , EXPR ).

V是集合 { EXPR , TERM , FACTOR } 且Σ是 { a , + , × , ( , ) }。作品有

V is the set { EXPR , TERM , FACTOR }, and Σ is { a , + , × , ( , ) }. The productions are

表达式 表达式+ 术语 | 学期 学期 学期× 系数 | 因子 因子 ( EXPR ) |

EXPR EXPR + TERM | TERM TERM TERM × FACTOR | FACTOR FACTOR ( EXPR ) | and

单词a+a× a(a+a)× a可以由语法G 4生成。

the words a+a× a and (a+a)× a can be generated by grammar G 4 .

这些词的解析树如下图所示。

The parse trees for these words are shown in the figure below.

2.5

单词a+a× a(a+a)× a 的解析树

Figure 2.5

Parse trees for the words a+a× a and (a+a)× a

编译器将以编程语言编写的代码转换为另一种形式,通常是更适合执行目的的形式。为此,编译器在称为解析的过程中提取要编译的程序的含义。这种含义的一种可能的表示是程序文本解析树,它是基于给定编程语言的上下文无关语法构建的。我们稍后在定理 7.16 和问题 7.45 中讨论上下文无关语言的解析算法。

A compiler translates code written in a programming language into another form, usually better suited for execution purposes. To do this, the compiler extracts the meaning of the program to be compiled in a process called parsing . One possible representation of this meaning is a parse tree of the program text, constructed based on the context-free grammar of the programming language. We discuss parsing algorithms for context-free languages ​​later, in Theorem 7.16 and Problem 7.45.

G 4语法描述了编程语言中处理算术表达式的部分。注意图 2.5 中的解析树是如何“分组”操作的。a+a× a的树将×运算符及其操作数(后两个a )分组为+运算符的一个操作数。在(a+a)× a的树中,分组顺序相反。这些分组与加法之前的标准乘法优先级相匹配,并使用括号来更改标准优先级。G 4语法旨在考虑这些优先级关系。

The grammar G 4 describes a section of the programming language dealing with arithmetic expressions. Notice how the parse trees in Figure 2.5 “group” the operations. The tree for a+a× a groups the operator × and its operands (the second two a s ) as one operand for the + operator . In the tree for (a+a)× a , the order of grouping is reversed. These groupings match the standard precedence of multiplication over addition and the use of parentheses to change the standard precedence. The grammar G 4 is designed to accommodate these precedence relationships.

设计上下文无关语法

Designing Context-Free Grammars

就像第 1.1 节(第 41 页)中讨论的设计有限自动机一样,设计上下文无关语法需要创造力。事实上,上下文无关语法甚至比有限自动机更难构建,因为我们更习惯于针对特定任务的编程机器,而不是通过语法来描述语言。当面临构建 CFG 语法的问题时,下面介绍的技术(单独或组合)可能会有所帮助。

Like the design of finite-state machines discussed in Section 1.1 (page 41), the design of context-free grammars requires creativity. In fact, context-free grammars are even more difficult to construct than finite-state machines, because we are more accustomed to programming machines for specific tasks than to describing languages ​​by grammars. The techniques presented below, individually or in combination, can be helpful when faced with the problem of constructing a CFG grammar.

首先,许多CFL语言是更简单的CFL语言的总和。如果我们需要为上下文无关语言构建一个可以分为更简单部分的语法,我们应该这样做并为每个部分构建单独的语法。通过将它们的产生式收集在一起并添加新的产生式S S 1 | ,可以轻松地将这些单独的语法合并到原始语言的语法中。S 2 | …… | S k,其中变量S i是各个语法的初始变量。解决许多简单的问题通常比解决一个复杂的问题更容易。

First, many CFL languages ​​are the sum of simpler CFL languages. If we need to construct a grammar for a context-free language that we can divide into simpler parts, we do so and construct individual grammars for each of those parts. These individual grammars can be easily merged into the grammar of the original language by collecting their productions together and adding a new production S S 1 | S 2 | … | S k , where the variables S and are the initial variables of the individual grammars. Solving many simpler problems is often easier than solving a single complex one.

例如,要获取语言的语法 { 0 n 1 n | n ≥ 0} { 1 n 0 n | n ≥ 0},我们首先构造语法

For example, to obtain a grammar for the language { 0 n 1 n | n ≥ 0} { 1 n 0 n | n ≥ 0}, we first construct the grammar

S 1 0 S 1 1 | ε

S 1 0 S 1 1 | ε

对于语言 { 0 n 1 n | n ≥ 0} 和语法

for the language { 0 n 1 n | n ≥ 0} and the grammar

S 2 1 S 2 0 | ε

S 2 1 S 2 0 | ε

对于语言 { 1 n 0 n | n ≥ 0},然后我们添加产生式S S 1 | S 2,最终产生语法

for the language { 1 n 0 n | n ≥ 0}, and then we add the production S S 1 | S 2 , finally obtaining the grammar

S S 1 | S 2

S S 1 | S 2

S 1 0 S 1 1 | ε

S 1 0 S 1 1 | ε

S 2 1 S 2 0 | ε。

S 2 1 S 2 0 | ε.

其次,为一种恰好是正则的语言构建CFG语法是很容易的,只要我们可以提前为该语言构建一个DFA。任何 DFA 都可以转换为等效的 CFG 语法,如下所示。我们为每个状态q这个 DFA创建一个变量R i 。如果 δ( q i , a ) = q j是 DFA 中的转移,我们将产生式R iaR j添加到 CFG 中。如果q i是 DFA 接受状态,我们添加产生式R i ε。该文法的初始变量R 0为本机初始状态q 0对应的变量。读者可以自己验证生成的 CFG 语法是否生成与 DFA 识别的语言相同的语言。

Second, constructing a CFG grammar for a language that happens to be regular is easy, provided we can first construct a DFA for that language. Any DFA can be converted into an equivalent CFG grammar in the following way. We create a variable R i for each state q i of the DFA. We add the production R i aR j to the CFG if δ( q i , a ) = q j is a transition in the DFA. We add the production R i ε if q i is a state that accepts the DFA. The initial variable R 0 of the grammar is the variable corresponding to the initial state q 0 of the machine. The reader can check for himself that the resulting CFG grammar generates the same language as the one recognized by the DFA.

第三,某些上下文无关语言包含由两个“相关”子词组成的单词,这种语言的机器必须记住有关这些子词之一的无限量信息,才能确定它是否与另一个正确对应。这就是 { 0 n 1 n : n ≥ 0} 语言中的情况,因为机器必须记住 0 的数量才能验证它是否等于 1 的数量。我们可以构建一个 CFG 语法来处理这种情况,方法是使用R u R v形式的产生式,生成单词,其中包含符号u 的部分对应于包含v 的部分。

Third, some context-free languages ​​contain words composed of two substrings that are "related" in the sense that a machine for such a language would have to remember an unlimited amount of information about one of the substrings in order to be able to check whether it corresponds correctly to the other. This situation occurs in the language { 0 n 1 n : n ≥ 0}, since the machine must remember the number of zeros in order to be able to verify whether it equals the number of ones. We can construct a CFG grammar that handles this situation using a production of the form R u R v , generating words in which the part containing symbols u corresponds to the part containing v .

最后,在更复杂的语言中,单词可能包含作为其他(或相同)结构的一部分递归出现的特定结构。这种情况发生在生成例 2.4 中的算术表达式的语法中。每当符号a出现时,括号中的整个表达式可能会递归出现。为了达到这种效果,我们将生成该结构的变量的符号放置在该结构可能出现的生产位置。

Finally, in more complex languages, words can contain special structures that recursively appear as part of other (or the same) structures. This is the case in the grammar that generates the arithmetic expressions of Example 2.4. Whenever the symbol a appears , the entire expression in parentheses can recursively appear in its place. To achieve this effect, we place the symbol of the variable that generates this structure at those places in the production where this structure would appear.

歧义

Ambiguity

有时语法可以用不同的方式生成同一个单词。这样的单词将有几个不同的解析树,因此有几个不同的含义。在某些应用程序(例如编程语言)中,此结果可能是不受欢迎的,因为程序应该具有唯一的解释。

Sometimes a grammar may generate the same word in different ways. Such a word will have several different parse trees and thus several different meanings. This result may be undesirable in some applications, such as programming languages, since a program should have a unique interpretation.

如果一个语法以多种不同的方式生成同一个单词,我们就说该单词在该语法中输出不明确。如果某个文法产生了一些歧义的单词,则该文法称为歧义文法

If a grammar generates the same word in many different ways, we say that the word is derived ambiguously in that grammar. If a grammar generates some words ambiguously, then the grammar is called ambiguous .

例如,考虑语法G 5

For example, consider the grammar G 5 :

〈EXPR〉〈EXPR〉+ 〈EXPR〉 |​表达式× 表达式 | ( EXPR ) |

EXPR EXPR + EXPR | EXPR × EXPR | ( EXPR ) | and

该语法模糊地生成单词a+a×a。下图展示了两种不同的解析树。

This grammar ambiguously generates the word a+a×a . The figure below shows two different parse trees.

2.6 G 5文法中

单词a+a× a的两棵划分树

Figure 2.6

Two parse trees for the word a+a× a in grammar G 5

该语法不考虑通常的运算顺序,因此可能会将 + 运算分组在 × 之前,反之亦然。相比之下,G 4语法生成完备相同的语言,但生成的每个单词都有一个唯一的解析树。因此,G 4是明确的,而G 5是模糊的。

This grammar ignores the usual order of operations, and thus can group the + operation before the × or vice versa. In contrast, the grammar G 4 generates exactly the same language, but each generated word has a unique parse tree. Thus, G 4 is unambiguous, while G 5 is ambiguous.

语法G 2(第 103 页)是歧义语法的另一个例子。“女孩用花触摸男孩”这句话有两种不同的推导。在练习 2.8 中,读者需要找到两个不同的剖析树,并注意它们与这句话的两种阅读方式的关系。

Grammar G 2 (page 103) is another example of ambiguous grammar. The sentence the girl touches the boy with the flower has two different derivations. In Exercise 2.8 the reader will have to find two different parse trees and note their connection with two ways of reading the sentence.

我们现在将模糊性的概念形式化。当我们说语法模糊地生成一个单词时,我们的意思是该单词有两个不同的解析树,而不是两个不同的派生。两个推导可能仅在变量替换的顺序上有所不同,而在它们的整体结构上没有不同。为了关注结构,我们定义了一个派生类型,其中变量以固定顺序替换。如果每一步都替换最左边的变量,则G文法中单词的推导就是左推导。定义 2.2(第 104 页)之前的推导是左手推导。

We now formalize the notion of ambiguity. When we say that a grammar ambiguously generates a word, we mean that the word has two different parse trees, not two different derivations. The two derivations may differ only in the order in which variables are substituted, but not in their overall structure. To concentrate on the structure, we define a type of derivation in which variables are substituted in a fixed order. A derivation of a word in a grammar G is a left-hand derivation if the leftmost variable is substituted at each step. The derivation preceding Definition 2.2 (page 104) is a left-hand derivation.

定义2.7

Definition 2.7

如果单词w有两个或多个不同的左手推导,则它在上下文无关语法G中的推导是不明确的。如果文法 G 产生的单词不明确,则该文法G不明确的。

A word w is derived ambiguously in a context-free grammar G if it has two or more distinct left-hand derivations. A grammar G is ambiguous if there is a word w that is generated ambiguously by this grammar.

有时,给定一个二义性语法,我们可以找到一个生成相同语言的明确语法。然而,一些上下文无关语言只能由二义性语法生成。这种语言被称为本质上模糊的。在问题 2.29 中,读者需要找到证据证明语言 { a i b j c k : i = j or j = k } 本质上是不明确的。

Sometimes, given an ambiguous grammar, we can find an unambiguous grammar that generates the same language. However, some context-free languages ​​can only be generated by ambiguous grammars. Such languages ​​are called inherently ambiguous . In Task 2.29, the reader will be required to find a proof that the language { a i b j c k : i = j or j = k } is inherently ambiguous.

乔姆斯基的范式

Chomsky normal form

当使用上下文无关语法时,以简化的形式呈现它们通常很方便。特别是,乔姆斯基范式是编写上下文无关语法的最简单和最有用的形式之一。这种形式对于指定在上下文无关语法上运行的算法很有用,我们将在第 4 章和第 7 章中进行操作。

When dealing with context-free grammars, it is often convenient to represent them in a simplified form. In particular, Chomsky normal form is one of the simplest and most useful forms of writing context-free grammars. This form is useful for specifying algorithms for operating on context-free grammars, which we will do in Chapters 4 and 7.

定义2.8

Definition 2.8

如果上下文无关文法的所有产生式都采用乔姆斯基范式

A context-free grammar is in Chomsky normal form if all of its productions are in the form

A BC A a

A BC A a

其中a是任意终结符,ABC是任意变量,但BC都不能是初始变量。此外,我们允许产生式S ε,其中S是初始变量。

where a is any terminal, and A , B , and C are any variables, except that neither B nor C can be an initial variable. Additionally, we allow the production S ε, where S is an initial variable.

定理2.9

Theorem 2.9

每种上下文无关语言都是由乔姆斯基范式上下文无关语法生成的。

Every context-free language is generated by a context-free grammar in Chomsky normal form.

证明的概念 我们可以将任何文法G转化为乔姆斯基范式。这种转变涉及多个阶段,其中违反条件​​的产品被满足条件的等效产品所取代。首先,我们添加一个新的起始变量。然后我们消除所有A ε形式的ε-产生式。我们还消除了A B形式的所有单元产生式。在这两种情况下,我们都会补充语法以确保生成相同的语言。最后,我们将剩余的产生式转换为所需的形式。

Proof Concept We can transform any grammar G into Chomsky normal form. This transformation involves multiple steps in which productions that violate the conditions are replaced by equivalent productions that satisfy them. First, we add a new initial variable. Then we eliminate all ε-productions of the form A ε. We also eliminate all singular productions of the form A B . In both cases, we complete the grammar to ensure that the same language is generated. Finally, we transform the remaining productions to the required form.

证明 首先,我们添加一个新的初始变量S 0和产生式S 0 S,其中S是原始初始变量。此更改可确保种子变量不会出现在任何产生式的右侧。

Proof First, we add a new initial variable S 0 and a production S 0 S , where S is the original initial variable. This change guarantees that the initial variable does not appear on the right-hand side of any production.

然后我们需要处理所有的ε-产生式。我们删除 ε-产生式A ε,其中A不是初始变量。然后,对于产生式右侧每次出现的变量A ,我们添加一个新的产生式并删除该出现。换句话说,如果R uAv是一个产生式,其中uv是变量和终结词,我们添加产生式R uv。我们对变量A的每次出现都执行此操作,因此产生式R uAvAw加上产生式R uvAwR uAvwR uvw。如果存在产生式R A,我们添加产生式R ε ,除非我们之前已经删除了产生式R ε 。我们重复这些步骤,直到消除所有未出现初始变量的 ε-产生式。

Next, we need to deal with all ε-productions. We remove the ε-production A ε where A is not an initial variable. Then, for each occurrence of A in the right-hand side of the production, we add a new production with that occurrence removed. In other words, if R uAv is a production where u and v are words of variables and terminals, we add the production R uv . We do this for each occurrence of A , so the production R uAvAw adds the productions R uvAw , R uAvw , and R uvw . If there is a production R A , we add the production R ε , unless we have already removed the production R ε . We repeat these steps until we have eliminated all ε-productions where the initial variable does not occur.

接下来,我们需要处理所有的链式生产。我们删除产生式A B。然后,对于B u形式的每个产生式,我们添加产生式A u,除非它是先前删除的链式产生式。和以前一样,u是变量和终结符的词。我们重复这些步骤,直到消除所有链式生产。

In the following, we need to deal with all chain productions. We remove the production A B . Then, for each production of the form B u , we add the production A u , unless it was a previously removed chain production. As before, u is a word of variables and terminals. We repeat these steps until we have eliminated all chain productions.

最后,我们将所有剩余的产生式转换为正确的形式。我们将A u 1 u 2 ...u k形式的每个产生式(其中k ≥ 3 并且每个u i是变量或终结符号)替换为产生式A u 1 A 1 , A 1 u 2 A 2A 2 u 3 A 3,…,A k -2 u k -1 u k新变量。我们用新变量U i替换先前产生式中的每个终端u i并添加产生式U iu i

Finally, we transform all remaining productions to the proper form. We replace each production of the form A u 1 u 2 …u k , where k ≥ 3 and each u i is a variable or terminal symbol, with the productions A u 1 A 1 , A 1 u 2 A 2 , A 2 u 3 A 3 , … , and A k −2 u k −1 u k . The A i are new variables. We replace each terminal u i in the previous productions with a new variable U i and add the production U iu i .

2.10

Example 2.10

G 6为以下CFG语法;我们将使用所示的转换过程将其转换为乔姆斯基范式。接下来显示的语法说明了转换步骤。粗体的产品是刚刚添加的产品。灰显的作品是那些刚刚被删除的作品。

Let G 6 be the following CFG grammar; we convert it to Chomsky Normal Form using the conversion procedure shown. The subsequent grammars shown illustrate the conversion steps. Productions in bold are those that have just been added. Productions in gray are those that have just been removed.

  1. 原始的G 6语法如左图所示。右侧是应用第一步并创建新的初始变量的结果。

  2. The original grammar G 6 is shown on the left. On the right is the result of applying the first step and creating a new initial variable.

  3. 我们删除左图所示的ε-产生式B ε,以及右图所示的A → ε。

  4. We remove the ε-productions B ε, which is shown on the left, and A ε, on the right.

  5. 我们删除链产生式S S(左侧)和S 0 S(右侧)。

  6. We remove the chain productions S S (on the left) and S 0 S (on the right).

  7. 我们删除链产生式A BA S。

  8. We remove the chain productions A B and A S .

  9. 我们将剩余的产生式转换为正确的形式,添加额外的变量和产生式。乔姆斯基范式的最终文法相当于G 6。 (事实上​​,定理 2.9 中给出的过程产生多个变量U i和多个产生式U i a。我们通过使用单个变量U和产生式U a简化了结果语法。)

  10. We convert the remaining productions to the proper form by appending additional variables and productions. The final grammar in Chomsky normal form is equivalent to G 6 . (In fact, the procedure given in Theorem 2.9 produces multiple variables U i and multiple productions U i a . We have simplified the resulting grammar by using a single variable U and productions U a .)

2.2

堆栈机

2.2

Stack machines

此时我们将介绍一种称为下推自动机(PDA)的新型计算模型。此类自动机类似于非确定性有限自动机,但也包含称为堆栈的组件。堆栈提供超出控件可用的有限内存量的额外内存。它允许堆叠自动机识别某些非正则语言。

In this section, we introduce a new type of computational model called a pushdown automaton ( PDA). Such automata are similar to nondeterministic finite automata, but they also contain a component called a stack . A stack provides additional memory beyond the finite amount available for control. It allows pushdown automata to recognize certain irregular languages.

就表达能力而言,堆叠自动机相当于上下文无关语法。这种等价性很有用,因为它提供了两种选项来证明语言是上下文无关的。我们可以提供一个生成它的上下文无关语法,或者一个识别它的堆栈自动机。有些语言更容易使用生成器来描述,而另一些语言则更容易通过识别它们的机器来描述。

Pushdown automata are equivalent in expressiveness to context-free grammars. This equivalence is useful because it gives us two options for proving that a language is context-free. We can either represent a context-free grammar that generates it, or a pushdown automaton that recognizes it. Some languages ​​are more easily described by generators, while others are more easily described by machines that recognize them.

下图显示了有限状态机的图。处理器表示状态和转换函数,磁带包含输入字,箭头表示指向下一个要读取的符号的读取头。

The following figure shows a diagram of a finite state machine. The processor represents the states and the transition function, the tape contains the input word, and the arrow symbolizes the reading head pointing to the next symbol to read.

2.11

有限状态机方案

Figure 2.11.

Schematic diagram of a finite state machine.

添加堆栈组件后,我们得到堆栈机的示意图,如下图所示。

After adding the stack component, we obtain the schematic of the stack machine shown in the next figure.

2.12

堆栈机示意图

Figure 2.12.

Schematic diagram of a stack automaton.

堆栈机可以将符号写入堆栈并稍后读取它们。写入一个符号会“下推”堆栈上的所有其他符号。堆栈顶部的符号可以随时读取和删除。这会将剩余的符号向上移动。将符号写入堆栈通常称为将符号推开push),并将符号堆栈中删除(pop)。请注意,对堆栈的所有访问(无论是读取还是写入)都只能在堆栈顶部执行。换句话说,堆栈是一个 LIFO(后进先出)存储设备。如果将某些信息写入堆栈并写入较晚的信息,则较早的信息将保持不可用,直到较晚的信息被删除。

A stack automaton can store symbols on the stack and read them later. Storing a symbol “pushes down” all the other symbols on the stack. The symbol at the top of the stack can be read and removed at any time. This causes the remaining symbols to be moved up. Storing a symbol on the stack is usually called pushing a symbol ( push ), and removing a symbol is popping a symbol ( pop ). Note that all access to the stack, both read and write, can only be performed on the top of the stack. In other words, the stack is a LIFO storage device ( last in , first out). If a piece of information is stored on the stack and more information is written later, the earlier piece of information is inaccessible until the later pieces of information are removed.

堆栈的示例可以是咖啡馆中的盘子分配器。这堆盘子靠在弹簧上,因此当在顶部添加新盘子时,下面的所有盘子都会向下移动。 PDA 堆栈类似于一叠盘子,每个盘子上都写有一个符号。

An illustration of a stack would be a plate dispenser in a café. The stack of plates rests on a spring, so when a new plate is added to the top, all the plates below it move down. A PDA stack is similar to a stack of plates, except that each plate has a symbol written on it.

堆栈是一个有价值的补充,因为它可以存储无限量的信息。回想一下,有限状态机无法识别语言 { 0 n 1 n : n ≥ 0},因为它无法在有限的内存中存储非常大的数字。 PDA 能够识别这种语言,因为它可以使用堆栈来存储读取的零的数量。堆栈的无限性质允许 PDA 存储无限大小的数字。以下非正式描述显示了该语言的自动机如何工作。

The stack is a valuable addition because it can store an unlimited amount of information. Recall that a finite state machine cannot recognize the language { 0 n 1 n : n ≥ 0} because it cannot store very large numbers in its limited memory. The PDA is able to recognize this language because it can use the stack to store the number of zeros read. The unlimited nature of the stack allows the PDA to store numbers of unlimited size. The following informal description shows how the machine works for this language.

从输入中读取符号。读取每个0 后,将它们压入堆栈。当出现 1 时,每读取1次就从堆栈中拉出一个 0。如果读取输入恰好在堆栈为空的时刻结束,则接受输入。如果堆栈为空,当还有任何1需要读取时,或者当1耗尽时,当堆栈仍然包含0 时,或者当 1 后面的输入中出现任何零时,丢弃该输入。

Read symbols from the input. After reading each 0 , push it onto the stack. As 1s appear, pop a 0 from the stack for each 1 read . If reading the input stops at the exact moment the stack becomes empty, accept the input. If the stack becomes empty while there are still 1s to read, or if the 1s run out while the stack still contains 0s , or if any zero appears on the input after the 1s, discard the input.

正如我们之前提到的,堆叠自动机可能是不确定的。确定性和非确定性堆叠自动机在表达能力方面并不等同。非确定性堆栈自动机可以识别确定性堆栈自动机无法识别的某些语言,我们将在 2.4 节中看到。我们将在示例 2.16 和 2.18 中呈现需要非确定性的语言。回想一下,确定性和非确定性有限自动机识别同一类语言,因此堆栈自动机的情况是不同的。我们将重点关注非确定性堆叠自动机,因为这些自动机在表达能力方面相当于上下文无关语法。

As mentioned earlier, pushdown automata can be nondeterministic. Deterministic and nondeterministic pushdown automata are not equivalent in expressiveness. Nondeterministic pushdown automata recognize some languages ​​that no deterministic pushdown automata can recognize, as we will see in Section 2.4. We will present languages ​​that require nondeterminism in Examples 2.16 and 2.18. Recall that deterministic and nondeterministic finite automata recognize the same class of languages, so the situation for pushdown automata is different. We will focus on nondeterministic pushdown automata, since these automata are equivalent to context-free grammars in expressiveness.

堆叠自动机的正式定义

Formal definition of a pushdown automaton

堆栈自动机的正式定义与有限自动机的定义类似,只是我们也有一个堆栈。它是一种包含从特定字母表中选择的符号的设备。机器可以使用不同的字母表作为输入和堆栈,因此我们将指定输入字母表Σ和堆栈字母表Γ

The formal definition of a pushdown automaton is similar to the definition of a finite state machine, except that here we have a stack. It is a device containing symbols chosen from some alphabet. The machine may use different alphabets for its inputs and for the stack, so we will specify both an input alphabet Σ and a stack alphabet Γ .

自动机的任何正式定义中的关键问题是提供描述其行为的传递函数。回想一下Σ ε = Σ {ε},以及Г ε = Г {ε}。传递函数的域为Q × Σ ε × Γ ε。所以栈机的下一步移动是由当前状态、下一个读取的输入符号和栈顶符号决定的。这些符号中的每一个都可以是 ε,导致机器状态发生变化,而无需从输入中读取符号或无需从堆栈中读取符号。

The key issue in any formal definition of an automaton is to provide a transition function that describes its behavior. Recall that Σ ε = Σ {ε}, and Γ ε = Γ {ε}. The domain of the transition function is Q × Σ ε × Γ ε . Thus, the next move of the push-pull automaton is determined by the current state, the next input symbol read, and the symbol at the top of the stack. Each of these symbols can be ε, causing the machine to change state without reading a symbol from the input or without reading a symbol from the stack.

当谈到传递函数的值时,我们需要考虑当自动机发现自己处于某种情况时我们将允许它做什么。它可能会进入其他状态,并可能将符号保存到堆栈顶部。 δ 函数可以通过返回Q 的元素和Γ ε的元素(即笛卡尔积Q × Γ ε的元素)来表示此类操作。由于我们在这个模型中允许非确定性,因此在任何给定情况下都可能有几个合法的下一步行动。传递函数将以通常的方式处理不确定性,即返回Q × Г ε的子集,即P ( Q × Г ε ) 的元素。最终,我们的传递函数 δ 变为 δ : Q × Σ × Γ ε P ( Q × Γ ε )。

In terms of the values ​​of the transition function, we need to consider what we allow the automaton to do when it finds itself in some particular situation. It can move to some other state and perhaps store a symbol on the top of the stack. The function δ can signal this action by returning an element of Q together with an element of Γ ε , that is, an element of the Cartesian product Q × Γ ε . Since we allow nondeterminism in this model, there can be several legal next moves in each situation. The transition function will handle nondeterminism in the usual way, by returning a subset of Q × Γ ε , that is, an element of P ( Q × Γ ε ). In the end, our transition function δ takes the form δ : Q × Σ × Γ ε P ( Q × Γ ε ).

定义 2.13

Definition 2.13

堆叠自动机是一个有序的六元组(6元组)( Q , Σ , Γ , δ , q 0 , F),其中所有集合Q , Σ , ΓF都是有限的并且

A pushdown automaton is an ordered six (6-tuple) ( Q , Σ , Γ , δ, q 0 , F ), where all sets Q , Σ , Γ and F are finite and

  1. Q是状态集,
  2. Q is a set of states,
  3. Σ是输入数据的字母表,
  4. Σ is the input data alphabet,
  5. Γ是堆栈字母表,
  6. Γ is the stack alphabet,
  7. δ : Q × Σ × Γ ε P ( Q × Γ ε ) 是传递函数,
  8. δ : Q × Σ × Γ ε P ( Q × Γ ε ) is the transition function,
  9. q 0 Q是初始状态,
  10. q 0 Q is the initial state,
  11. F Q是接受状态的集合。
  12. F Q is the set of accepting states.

具有堆栈M = ( Q , Σ , Γ , δ, q 0 , F ) 的自动机按以下方式执行计算。接受输入单词w,如果w可以写为w = w 1 w 2 …w m,其中每个w i Σ ε并且存在状态序列r 0 , r 1 , …, r m Q和单词s 0 , s 1 , …, s m Γ ε , 使得满足以下三个条件。单词s代表接受计算路径上后续步骤中机器M的堆栈内容。

An automaton with a stack M = ( Q , Σ , Γ , δ, q 0 , F ) performs its computations in the following way. It accepts an input word w , if w can be written as w = w 1 w 2 …w m , where each w i Σ ε and there exists a sequence of states r 0 , r 1 , …, r m Q and words s 0 , s 1 , …, s m Γ ε , such that the following three conditions are satisfied. The words s i represent the contents of the stack of the automaton M in subsequent steps on the accepting computation path.

  1. r 0 = q 0s 0 = ε。该条件表明M应该以初始状态和空堆栈开始。
  2. r 0 = q 0 and s 0 = ε. This condition states that M is to start in the initial state and with an empty stack.
  3. 对于i = 0, …, m − 1, ( r i +1 , b ) ε δ( r i , w i +1 , a )成立,其中s i = ats i +1 = bt对于某些ab Г εt Г *。该条件表明M根据当前状态、堆栈内容和下一个输入符号移动到下一个状态。
  4. For i = 0, …, m − 1, ( r i +1 , b ) δ( r i , w i +1 , a ), where s i = at and s i +1 = bt for some a , b Γ ε and t Γ * , holds. This condition states that M transitions to the next state based on the current state, the stack contents, and the next input symbol.
  5. r m F。该条件表明,当到达输入字的末尾时,出现接受状态。
  6. r m F . This condition states that the accepting state occurs when the end of the input word is reached.

堆叠机器示例

Examples of stack machines

2.14

Example 2.14

下面是识别语言 { 0 n 1 n : n ≥ 0} 的 PDA(第 112 页)的正式描述。令M 1为 ( Q , Σ , Γ , δ, q 1 , F ),其中

Below is a formal description of a PDA (page 112) that recognizes the language { 0 n 1 n : n ≥ 0}. Let M 1 be ( Q , Σ , Γ , δ, q 1 , F ), where

Q = { q 1 , q 2 , q 3 , q 4 },

Q = { q 1 , q 2 , q 3 , q 4 },

Σ = { 0 , 1 },

Σ = { 0 , 1 },

γ = { 0 , $ },

Γ = { 0 , $ },

F = { q 1 , q 4 },并且

F = { q 1 , q 4 }, and

δ 由下表给出,其中空白条目代表Ø

δ is given by the table below, where blank entries represent Ø .

我们还可以使用状态图来描述 PDA,如图 2.15、2.17 和 2.19 所示。此类图类似于用于描述有限状态机的状态图,但进行了修改,显示了 PDA 在从一个状态移动到另一个状态时如何使用其堆栈。我们使用符号“ a , b c ”来表示当机器从输入中读取符号a时,它可以用符号c替换栈顶的符号babc中的任何一个都可以是空词 ε。如果a是 ε,则机器可以执行此转换,而无需从输入中读取任何符号。如果b是 ε,则机器可以执行转换,而无需从堆栈中读取或弹出任何符号。如果c等于 ε,则机器在执行此转换时不会将任何符号写入堆栈。

We can also use a state diagram to describe a PDA, as in Figures 2.15, 2.17, and 2.19. Such diagrams are similar to the state diagrams used to describe finite state machines, but with the modification of showing how the PDA uses its stack to transition from state to state. We use the notation “ a , b c ” to indicate that when the machine reads symbol a from the input , it can replace symbol b at the top of the stack with symbol c . Any one of a , b , or c can be the empty word ε . If a is ε , the machine can make this transition without reading any symbol from the input. If b is ε , the machine can make this transition without reading or popping any symbol from the stack. If c is ε , the machine does not write any symbol to the stack when making this transition.

2.15 PDA M 1识别语言 { 0 n 1 n : n ≥ 0}

的状态图

Figure 2.15

State diagram for a PDA M 1 recognizing the language { 0 n 1 n : n ≥ 0}

PDA的正式定义不包括任何显式的机制来测试堆栈是否为空。该老虎机通过最初将特殊符号$放入堆栈来实现此效果。然后,每当它再次看到$时,它就会知道堆栈实际上是空的。每当我们稍后在PDA的非正式描述中提到检查堆栈是否为空时,我们都会以相同的方式实现这个过程。

The formal definition of a PDA does not include any explicit mechanism for performing a test to see if the stack is empty. This automaton is able to do this by initially pushing the special symbol $ onto the stack . Then, whenever it sees $ again , it will know that the stack is indeed empty. Whenever we refer later in informal descriptions of PDAs to checking if the stack is empty, we will implement this procedure in the same way.

类似地,PDA 无法明确检查它是否已到达输入单词的末尾。这个PDA可以达到这个效果,因为只有当机器处于输入结束时才将接受状态视为这样。从这里开始,我们假设 PDA 可以测试输入的结尾,并且我们知道我们可以以相同的方式实现它。

Similarly, a PDA cannot explicitly check whether it has reached the end of an input word. This PDA can achieve this effect because the accepting state is treated as such only when the machine is at the end of the input. From here on, we will assume that PDAs can test for the end of the input, and we know that we can implement this in the same way.

2.16

Example 2.16

此示例说明了语言感知堆栈机

This example illustrates a stack machine that recognizes a language.

{ a i b j ck : i , j , k ≥ 0 且i = ji = k }。

{ a i b j c k : i , j , k ≥ 0 and i = j or i = k }.

通俗地说,这种语言的 PDA 的工作原理是首先读取下一个a并将其推入堆栈。一旦机器完成读取a ,它就会将它们全部放入堆栈中,因此它可以将它们与下一个bc匹配。这个操作有点复杂,因为机器事先不知道是否应该将符号a与符号bc匹配。这就是非决定论派上用场的地方。

Informally, the PDA for this language works by first reading the next a and pushing it onto the stack. Once the machine has finished reading the a , it has all of them on the stack, so it can match them either with the next b , or with c . This maneuver is a bit tricky, because the machine doesn't know in advance whether it should match the symbols a with b , or with c . This is where nondeterminism comes in handy.

利用PDA的非确定性,它可以猜测是否将符号a与符号b或符号c匹配,如图2.17所示。我们可以将这台机器视为具有两个非决定论分支,一个分支对应这些可能性中的每一种。如果其中之一匹配,则该路径接受输入,因此整个机器都会接受它。在问题 2.57 中,有必要证明这种非确定性是使用 PDA 识别这种语言的基础。

Using the nondeterminism of the PDA, it can guess whether to match symbols a to symbols b or c , as in Figure 2.17. We can think of this machine as having two branches of nondeterminism, one for each of these possibilities. If either path matches, that path accepts the input, and so the whole machine accepts it. In Problem 2.57 we will have to show that such nondeterminism is essential for recognizing this language using a PDA.

2.17 PDA M 2识别语言 { a i b j c k : i , j , k ≥ 0 and i = j or i = k }

的状态图

Figure 2.17

State diagram for a PDA M 2 that recognizes the language { a i b j c k : i , j , k ≥ 0 and i = j or i = k }

2.18

Example 2.18

在此示例中,我们将展示一个可识别语言 { ww R : w { 0 , 1 } * } 的PDA M 3。回想一下,w R表示w以相反的顺序书写。下面是该 PDA 的非正式描述和状态图。

In this example, we introduce a PDA M 3 that recognizes the language { w w R : w { 0 , 1 } * }. Recall that w R denotes w written in reverse order. Below is an informal description and state diagram for this PDA.

我们首先将下一个读取的符号放入堆栈。在每个点上,我们不确定地猜测我们已经到达单词的中间,并将操作更改为从每个读取的符号的堆栈中弹出符号,检查它们是否相同。如果它始终是相同的符号,并且堆栈在输入单词结束的同一时刻清空,我们接受该单词;在任何其他情况下,我们都会拒绝他们。

We start by pushing symbols onto the stack as they are read. At each point, we nondeterministically guess that we have reached the middle of a word, and change the operation to popping symbols off the stack for each symbol read, checking that they are the same. If it is always the same symbol and the stack empties at the same time as the input word ends, we accept the word; otherwise, we discard it.

2.19 PDA M 3识别语言 { ww R : w { 0 , 1 } * }

的状态图

Figure 2.19

State diagram for a PDA M 3 recognizing the language { ww R : w { 0 , 1 } * }

在问题 2.58 中,我们将证明该语言需要使用非确定性 PDA。

In Exercise 2.58 we will show that this language requires the use of a nondeterministic PDA.

与上下文无关语法的等价

Equivalence with context-free grammars

在本节中,我们将证明上下文无关语法和堆叠自动机在表达能力方面是等效的。两种机制都能够描述一类上下文无关语言。我们将展示如何将任何上下文无关语法转换为识别相同语言的基于堆栈的自动机,反之亦然。回想一下,我们将上下文无关语言定义为可以使用上下文无关语法描述的任何语言,因此我们的目标是证明以下定理。

In this section, we will show that context-free grammars and pushdown automata are equivalent in expressiveness. Both mechanisms are capable of describing the class of context-free languages. We will show how to transform any context-free grammar into a pushdown automaton recognizing the same language, and vice versa. Recall that we defined a context-free language as any language that can be described by a context-free grammar, so our goal is to prove the following theorem.

定理2.20

Theorem 2.20

一种语言是上下文无关的当且仅当它被某些基于堆栈的自动机识别时。

A language is context-free if and only if it is recognized by some pushdown automaton.

与“当且仅当”陈述一样,我们需要在两个方向上证明。这个主张有两个有趣的方向。我们将首先解决更容易的“前进”方向。

As always with "if and only if" theorems, we need to do the proof in both directions. There are two directions of interest in this theorem. We'll first consider the easier "forward" direction.

引理 2.21

Lemma 2.21

如果一种语言是上下文无关的,则有一些堆栈自动机可以识别它。

If a language is context-free, there is some stack automaton that recognizes it.

证明的概念 A是一种 CFL 语言。根据定义,我们知道对于语言A,有一个生成它的CFG 语法G。我们将展示如何将G转换为等效的PDA,我们将其称为P。

Proof Concept Let A be a CFL language. By definition, we know that for A there exists a CFG grammar G that generates it. We will show how to transform G into an equivalent PDA, which we will call P .

我们在这里描述的PDA P将通过接受输入单词w(如果G生成该单词)来进行操作,并确定该语法中是否存在w的派生。回想一下,派生只是语法生成单词时进行的一系列替换。每个推导步骤都会产生变量和终结符的中间字。我们将设计P来确定使用语法G的产生式的特定替换序列是否可以从初始变量通向w

The PDA P that we will describe here will operate by accepting an input word w if G generates that word, determining whether there is a derivation for w in the grammar. Recall that a derivation is simply a sequence of substitutions performed as the word is generated by the grammar. Each step of the derivation yields an intermediate word of variables and terminals. We will design P to determine whether some sequence of substitutions using the productions of the grammar G can lead from an initial variable to w .

测试w是否可以推导的困难之一是确定应该进行哪些替换。 PDA 的不确定性使其能够猜测正确替换的顺序。在每个推导步骤中,不确定地选择特定变量的产生式之一并用于替代该变量。

One of the difficulties of testing whether a derivation for w can exist is determining what substitutions to make. The nondeterminism of PDA allows it to guess the sequence of correct substitutions. At each step of the derivation, one of the productions for a particular variable is nondeterministically chosen and used to substitute for that variable.

PDA P首先将初始变量写入堆栈。然后它会经历一系列中间单词,逐个进行替换。最终,它可能会得到一个仅包含终结符号的单词,这意味着它已经使用语法来推导该单词。如果输入字与输出字相同,则P接受输入字。

PDA P starts by storing an initial variable on the stack. It then traverses a series of intermediate words, performing substitutions one by one. Eventually, it may reach a word that contains only terminal symbols, which means that it used a grammar to derive that word. P accepts the input word if it is identical to the derived word.

在 PDA 中实施此策略需要额外的想法。

Implementing this strategy in PDA requires additional thought.

我们需要确定 PDA 如何存储中间单词以及如何将其从一个单词移动到另一个单词。在堆栈上存储中间字很诱人,但它不能正常工作,因为 PDA 必须查找变量并执行替换。 PDA只能访问堆栈顶部的符号,并且那里可能有终结符,而不是变量。解决方法是仅存储以堆栈上第一个变量开头的中间字部分。出现在第一个变量之前的任何终止符号都直接与输入字中的符号匹配。 PDA P如下图所示。

We need to figure out how the PDA will store the intermediate words and how it will move from one to the next. Storing the intermediate words on the stack is tempting, but it doesn't work properly because the PDA has to look up variables and perform substitutions. The PDA can only access the symbol at the top of the stack, and that may be a terminal symbol, not a variable. The workaround is to store only that part of the intermediate word on the stack that starts with the first variable. Any terminal symbols that appear before the first variable are directly matched to symbols in the input word. The PDA P is shown in the figure below.

2.22

P代表中间序列01 A 1 A 0

Figure 2.22

P representing the intermediate sequence 01 A 1 A 0

下面的列表提供了P的非正式描述。

The list below provides an informal description of P .

  1. $标记符号和起始变量放在堆栈上。
  2. Put a $ marker symbol and an initial variable on the stack.
  3. 不间断地重复以下步骤。
    1. 如果堆栈顶部是变量符号A,则不确定地选择A的产生式之一,并将该产生式右侧的单词替换为A。
    2. 如果堆栈顶部有终结符a,则从输入中读取下一个符号并将其与a进行比较。如果符号匹配,则继续。如果不匹配,则丢弃该计算路径。
    3. 如果栈顶有$符号,则转入接受状态。只要已完整阅读输入的单词,就接受它。
  4. Repeat the following steps continuously.
    1. If the symbol of the variable A is at the top of the stack , nondeterministically choose one of the productions for A and substitute A with the word on the right side of that production.
    2. If the terminal symbol a is at the top of the stack , read the next symbol from the input and compare it to a . If the symbols match, continue. If they do not match, discard this path of computation.
    3. If the top of the stack is $ , enter the accepting state. Accept the input word if it has been read completely.

证明我们现在给出堆栈自动机P = ( Q , Σ , Γ , δ , q start , F ) 的形式细节为了使结构更加清晰,我们将对传递函数使用简化的符号。这种表示法提供了一种在一个机器步骤中在堆栈上打印整个单词的方法。我们可以通过引入一次写一个符号的附加状态来模拟这种行为,我们将在构造的正式描述中这样做。

Proof We now present the formal details of the pushdown automaton P = ( Q , Σ , Γ , δ, q start , F ). To make the construction more transparent, we use a simplified notation for the transition function. This notation provides a way to write out the entire word on the stack in a single step of the machine. We can simulate this operation by introducing additional states that write out the word one symbol at a time, which we will do in the formal description of the construction.

qr为 PDA 状态,并令a属于Σ εs属于Γ ε。假设我们希望 PDA在读取a并从堆栈中弹出s时从状态q移动到r。此外,我们希望它同时将整个单词u = u 1 ... u l压入堆栈。我们可以通过引入新状态q 1 , …, q l −1并设置转换函数来实现此行为,如下所示:

Let q and r be states of the PDA and let a be a member of Σ ε and s be a member of Γ ε . Suppose we want the PDA to transition from state q to r when it reads a and pops s from the stack . Moreover, we want it to push an entire word u = u 1u l onto the stack at the same time . We can implement this by introducing new states q 1 , …, q l −1 and setting the transition function as follows:

δ( q , a, s ) 包含 ( q 1 , u l ),

δ( q , a, s ) has to contain ( q 1 , u l ),

δ( q 1 , ε , ε ) = {( q 2 , u l −1 )},

δ( q 1 , ε, ε) = {( q 2 , u l −1 )},

δ( q 2 , ε , ε ) = {( q 3 , u l −2 )},

δ( q 2 , ε, ε) = {( q 3 , u l −2 )},

...

...

δ( q l −1 , ε , ε ) = {( r , u 1 )}。

δ( q l −1 , ε, ε) = {( r , u 1 )}.

我们将使用符号 ( r , u ) ε δ( q , a , s ) ,当q是机器的状态时,a是下一个输入符号,s是堆栈顶部的符号,PDA 可以读取a并将s从堆栈中删除,然后将字u压入堆栈并移动到状态r。该实现如下图所示。

We will use the notation ( r , u ) δ( q , a , s ) in the sense that when q is a state of the automaton, a is the next input symbol, and s is the symbol on the top of the stack, the PDA can read a and pop s from the stack, then push the word u onto the stack and go to state r . This implementation is shown in the figure below.

2.23

简化的实现 ( r , xyz ) ε δ( q , a , s )

Figure 2.23

Implementation of the simplification ( r , xyz ) δ( q , a , s )

P的状态为Q = { q start , q Loop , q Accept } E,其中E是实现刚刚描述的简化所需的状态集。初始状态是q start。唯一的接受状态是q Accept

The states P are Q = { q start , q loop , q accept } E , where E is the set of states needed to implement the simplification just described. The initial state is q start . The only accepting state is q accept .

我们定义转移函数如下。我们首先初始化堆栈以包含符号$S,这实现了非正式描述的第一步:δ( q start , ε, ε) = {( q Loop , S $ )}。然后,我们将为步骤 2 中的主循环创建转换。

We define the transition function as follows. We start by initializing the stack to contain the symbols $ and S , which implements step one of the informal description: δ( q start , ε, ε) = {( q loop , S $ )}. We then create transitions for the main loop from step 2.

首先,我们将处理情况 (a),其中堆栈顶部有一个变量。令δ( qloop ,ε, A ) ={( qloop , w ): A w是G中的产生式}。

First, we handle the case (a) when a variable is at the top of the stack. Let δ( q loop , ε, A ) = {( q loop , w ) : A w be a production in G }.

其次,我们将处理堆栈顶部有终端的情况(b )。设 δ( q, a , a ) = {( q, ε)}。

Secondly, we handle the case ( b ) when there is a terminal at the top of the stack. Let δ( q loop , a , a ) = {( q loop , ε)}.

最后,我们将处理堆栈顶部有一个空堆栈标记$ 的情况 ( c ) 。设 δ( q循环, ε , $ ) = {( q接受, ε )}。

Finally, we handle the case ( c ) when the stack has an empty stack token $ at its top . Let δ( q loop , ε, $ ) = {( q accept , ε)}.

状态图如图2.24所示。

The state diagram is shown in Figure 2.24.

2.24 P

机状态图

Figure 2.24

State diagram of the machine P

这就完成了引理2.21的证明。

This completes the proof of Lemma 2.21.

2.25

Example 2.25

我们将使用引理 2.21 的证明中开发的过程从以下 CFG语法G构造 PDA P 1 。

We will use the procedure developed in the proof of Lemma 2.21 to construct the PDA P 1 from the following CFG grammar G .

S a T b |

S a T b | b

T T a | ε

T T a | ε

转换函数如下图所示。

The transition function is shown in the diagram below.

2.26 P 1

机状态图

Figure 2.26

State diagram of the machine P 1

现在我们将证明定理 2.20 的相反方向。接下来,我们构建了一个将 CFG 语法转换为 PDA 的程序。主要想法是设计一个模拟语法的自动机。现在我们想要提供一个相反方向的过程:将 PDA 转换为 CFG 语法。我们将设计语法来模拟自动机。这项任务并不容易,因为“编程”自动机比“编程”语法更容易。

We now prove the converse of Theorem 2.20. In the forward direction, we have constructed a procedure that transforms a CFG grammar into a PDA. The main idea was to design an automaton that simulates the grammar. Now we want to give a procedure that works in the opposite direction: transforming a PDA into a CFG grammar. We will design a grammar that simulates an automaton. This task is not easy, since “programming” an automaton is easier than “programming” a grammar.

引理2.27

Lemma 2.27

如果堆栈机识别一种语言,那么它就是上下文无关语言。

If a pushdown automaton recognizes any language, it is a context-free language.

证明的概念 我们有一个 PDA P,我们想要创建一个 CFG 语法G来生成P接受的所有单词。换句话说,如果G导致PDA从初始状态转变到接受状态,则G应该生成一个词。

Proof Concept We have a PDA P and we want to create a CFG grammar G that generates all words accepted by P . In other words, G should generate a word if it causes the PDA to transition from its initial state to an accepting state.

为了实现这个结果,我们将设计一个能做更多事情的语法。对于属于P 的每一对状态pq 文法中都会有一个变量A pq。该变量生成可以将P从具有空堆栈的状态p带到具有空堆栈的状态q 的所有字。请注意,这些字也可以将Pp移动到q,而不管状态p中堆栈的内容如何,​​在移动到状态q后以与状态p中相同的形式离开堆栈。

To achieve this result, we design a grammar that does a bit more. For each pair of states p and q that belong to P , the grammar has a variable A pq . This variable generates all the words that can take P from state p with an empty stack to state q with an empty stack. Note that such words can also take P from p to q regardless of the contents of the stack in state p , leaving the stack after the transition to state q in the same form that it had in state p .

首先,我们将通过稍微修改机器P来简化我们的句子,赋予它以下三个属性。

First, we simplify our statement by slightly modifying the automaton P to give it the following three properties.

  1. 它只有一种接受状态,q Accept
  2. It has only one accepting state q accept .
  3. 在接受之前清空堆栈。
  4. Empty the stack before accepting.
  5. 每个转换要么将一个符号推入​​堆栈(入栈移动),要么从堆栈中删除一个符号(弹出移动),但不会同时执行这两项操作。
  6. Each transition either pushes a symbol onto the stack (a push move ) or pops one off the stack (a pop move ), but it does not do both at the same time.

赋予机器P属性 1 和 2 很容易。为了获得属性 3,我们需要用经过新状态的两个转换序列来替换每个既弹出又推入某些内容到堆栈上的转换,并将每个既不弹出也不将任何东西推入堆栈的转换替换为两个转换序列首先将任何选定的符号放在一边,然后从堆栈中删除的转换。

Giving P properties 1 and 2 is easy. To obtain property 3, we must replace each transition that simultaneously pops and pushes something onto the stack by a sequence of two transitions that goes through the new state, and each transition that neither pops nor pushes anything onto the stack by a sequence of two transitions that first pushes and then pops an arbitrarily chosen symbol.

为了能够设计G以便变量A pq生成导致Pp移动到q的所有单词(以空堆栈开始和结束),我们需要了解P如何对这些单词进行操作。对于每一个这样的类似地,单词x的最后一次移动必须弹出,因为堆栈最后必须为空。

In order to design G so that the variable A pq generates all the words that cause P to move from p to q , starting and ending with an empty stack, we need to understand how P operates on those words. For any such word x, the first move of P must be push , since every move is either push or pop , and it is impossible to pop anything from an empty stack. Similarly, the last move for word x must be pop , since the stack is to be empty at the end.

P处理x时有两种可能。最后从堆栈中删除的符号要么是在操作开始时压入堆栈的符号,要么是另一个符号。第一种情况,栈只能在计算的最开始和最结束时为空。在第二种情况下,在读取整个单词x之前,必须在某个时刻将最初存放的符号从堆栈中弹出,因此堆栈随后变空。我们将使用产生式A pqaA rs b来模拟第一种可能性,其中a是在第一次移动中读取的输入,b在最后一次移动中读取,r是p之后的状态,s是 p 之前的状态q .我们将通过生成A pqA pr A rq来模拟第二种可能性,其中r是堆栈为空的状态。

There are two possibilities when P processes x . The symbol popped at the end is either the symbol that was pushed at the beginning of the computation or it is a different symbol. In the first case, the stack can be empty only at the very beginning and at the very end of the computation. In the second case, the symbol that was initially pushed must have been popped at some point before the entire word x was read , so the stack is then empty. We simulate the first of these possibilities using the production A pq aA rs b , where a is the input read on the first move, b is read on the last move, r is the state after p , and s is the state before q . We simulate the second possibility with the production A pq A pr A rq , where r is the state in which the stack is emptied.

证明 让我们假设P = ( Q , Σ , Γ , δ, q 0 , q Accept ) 并构造G G 的变量为 { A pq : p , q Q }。初始变量为Aq 0 ,q Accept G作品可分为三组。

Proof Let us assume that P = ( Q , Σ , Γ , δ, q 0 , q accept ) and construct G . The variables of G will be { A pq : p , q Q }. The initial variable is Aq 0 ,q accept . The productions of G can be divided into three groups.

  1. 对于所有p , q , r , s ε Q , u ε Γa , b ε Σ ε,如果 δ( p , a , ε) 包含 ( r , u ) 且 δ( s , b , u ) 包含 ( q , ε),我们将产生式A pqaA rs b添加到G中。
  2. For each p , q , r , s Q , u Γ and a , b Σ ε , if δ( p , a , ε) contains ( r , u ) and δ( s , b , u ) contains ( q , ε ), we add to G the production A pq aA rs b .
  3. 对于每个p , q , r Q我们将产生式A pqA pr A rq插入到G中。
  4. For every p , q , r Q we insert into G the production A pq A pr A rq .
  5. 最后,对于每个p Q,我们将产生式A pp → ε 添加到G中。
  6. Finally, for each p Q we add to G the production A pp ε.

下图提供了对该结构的一些了解。

The following drawings provide some insight into this construction.

2.28产生式A pqA pr A rq

对应的 PDA 计算

Figure 2.28

PDA calculations corresponding to the production A pq A pr A rq

2.29产生式A pqaA rs b

对应的 PDA 计算

Figure 2.29

PDA calculations corresponding to the production A pq aA rs b

现在,我们可以通过证明A pq生成单词x当且仅当x可以将自动机P从空堆栈状态p转换为空堆栈状态q来证明此构造有效。我们将作为单独的声明来演示每个方向。

We can now prove that this construction works by demonstrating that A pq generates a word x if and only if x can take an automaton P from state p with an empty stack to state q with an empty stack. We will show each direction as a separate statement.

声明2.30

Statement 2.30

如果A pq生成单词x,则x可以将机器P从空栈状态p带到空栈状态q 。

If A pq generates word x , then x can move automaton P from state p with an empty stack to state q with an empty stack.

我们将通过归纳从变量A pq导出x的步骤数来证明这个命题。

We will prove this statement by induction on the number of steps in the derivation of x from the variable A pq .

基本步骤:推导包含一个步骤。

Basic Step : Derivation contains one step.

一步推导必须使用右侧不包含变量的产生式。G中唯一没有右侧变量的产生式是A pp ε。很明显,输入ε将Pp空栈状态移动到p空栈状态,因此我们证明了基本步骤的正确性。

A one-step derivation must use a production whose right-hand side contains no variables. The only production in G that has no variables on the right-hand side is A pp ε. It is clear that the input ε moves P from state p with an empty stack to state p with an empty stack, so we have proven the validity of the basic step.

归纳步骤:对于长度至多为k的推导,假设该命题为真,其中k ≥ 1,并证明对于长度为k + 1的推导,该命题为真。

Inductive step : Assume the statement is true for derivations of length at most k , where k ≥ 1, and prove it for derivations of length k + 1.

假设A pq * x k +1步。该推导的第一步是A pq aA rs bA pq A pr A rq。我们将分别处理这两种情况。

Suppose that A pq * x by k +1 steps. The first step of this derivation is either A pq aA rs b , or A pq A pr A rq . We will deal with these two cases separately.

在第一种情况下,考虑由A rs生成的单词x的y部分,因此x = ayb。由于A rs* yk步中,归纳假设意味着P可以从具有空堆栈的状态r转到具有空堆栈的状态s 。由于A pqaA rs b是G的产生式,因此 δ( p , a , ε) 包含 ( r , u ) 且 δ( s , b , u ) 包含 ( q , ε) ,其中u是堆 。因此,如果P从p开始且堆栈为空,则在读取a后,它可以进入状态r并将u压入堆栈。然后读取单词y可以将其移动到状态s,将u留在堆栈上。然后,在读取b之后,它可以进入状态q并将u从堆栈中删除。因此,x可以将自动机从具有空堆栈的状态p带到具有空堆栈的状态q 。

In the first case, consider the part y of word x generated by A rs , so that x = ayb . Since A rs* y in k steps, the inductive hypothesis implies that P can move from state r with an empty stack to state s with an empty stack. Since A pqaA rs b is a production from G , δ( p , a , ε) contains ( r , u ) and δ( s , b , u ) contains ( q , ε ), where u is some symbol on the stack. Thus, if P starts at p with an empty stack, after reading a it can move to state r and push u onto the stack. Then reading word y can move it to state s , leaving u on the stack. Then after reading b it can move to state q and pop u from the stack. Therefore, x can take the automaton from state p with an empty stack to state q with an empty stack.

在第二种情况下,考虑单词x的yz部分,分别由A prA rq生成,即x = yz。由于A pr* y至多k步,A rq* z至多k步,归纳假设意味着y可以将自动机P从状态p带到状态r,而z可以将P从状态r带到状态 r 。状态q,在这两种情况下,计算开始和结束时堆栈均为空。因此,x可以将自动机从状态p移动到具有空堆栈的状态q 。这样就完成了归纳步骤。

In the second case, consider the parts y and z of x , generated by A pr and A rq , respectively, that is, x = yz . Since A pr * y in at most k steps and A rq * z in at most k steps, the inductive hypothesis implies that y can take P from state p to state r , and z can take P from state r to state q, in both cases with an empty stack at the beginning and end of the computation. Thus, x can take P from state p to state q with an empty stack. This completes the inductive step.

声明2.31

Statement 2.31

如果x可以将自动机P从空栈状态p带到空栈状态q ,则A pq生成x

If x can take an automaton P from state p with an empty stack to state q with an empty stack, then A pq generates x .

我们通过归纳P执行的计算步骤数来证明这一点,对于输入x,从状态pq 的开头和结尾都是空堆栈。

We prove this by induction on the number of computation steps performed by P that lead from state p to q with an empty stack at the beginning and end, for input x .

基本步骤:计算包含 0 个步骤。

Basic Step : The calculation contains 0 steps.

如果计算有 0 个步骤,则它以相同的状态开始和结束 - 比如说p。因此我们必须证明A pp * x。步长为 0 时,P无法读取任何字符,因此x = ε。根据构造,我们知道G包含产生式A pp ε,从而证明了基本步骤的正确性。

If the computation has 0 steps, then it starts and ends in the same state—say p . We therefore need to show that A pp * x . With 0 steps, P cannot read any characters, so x = ε. By construction, we know that G contains the production A pp ε , so we have proven the validity of the basic step.

归纳步骤:我们将假设对于长度至多为k的计算语句为真,其中k ≥ 0,并证明它对于长度k + 1 的计算为真。

Inductive step : We will assume the statement is true for computations of length at most k , where k ≥ 0, and prove it is true for computations of length k + 1.

假设P包含一个计算,其中x将机器从状态p带到状态q,并且在开始和结束处都有一个空堆栈,步骤为k + 1。堆栈可以仅在计算的开始和结束时为空,也可以在其他地方也变空。在第一种情况下,第一步中放入堆栈的符号必须与最后一步中从堆栈中删除的符号相同。我们称这个符号为u。令a为第一步读取的输入符号,b为最后一步读取的输入符号,r为第一次移动之后的状态,s为最后一次移动之前的状态。则 δ( p , a , ε) 包含 ( r , u )δ( s , b , u ) 包含 ( q , ε) ,因此A pq aA rs b属于G。

Suppose P contains a computation in which x takes the automaton from state p to state q with an empty stack at the start and end, in k + 1 steps. The stack can either be empty only at the start and end of this computation, or it becomes empty at some other point as well. In the first case, the symbol that is pushed onto the stack in the first move must be the same symbol that is popped off the stack in the last step. Let us call this symbol u . Let a be the input symbol read in the first step, b be the input symbol read in the last step, r be the state after the first move, and s be the state before the last move. Then δ( p , a , ε) contains ( r , u ), and δ( s , b , u ) contains ( q , ε ), so A pq aA rs b belongs to G .

消除a和 b后,令y成为x的一部分,即x = ayb。输入y可以将P从状态r移动到状态s ,而不更改堆栈上的符号u ,因此P可以从具有空堆栈的状态r移动到具有输入y的空堆栈的状态s。我们删除了x的原始计算的k +1 步中的第一步和最后一步,因此y的计算包含 ( k + 1) − 2 = k − 1。因此,归纳假设意味着A rs* y。因此A pq* x

Let y be the part of x after discarding a and  b , so x = ayb . Input y can move P from state r to state s without changing the symbol u on the stack, so P can go from state r with an empty stack to state s with an empty stack for input y . We have removed the first and last steps of the k + 1 steps of the original computation for x , so the computation for y contains ( k + 1) − 2 = k − 1. The inductive hypothesis therefore implies that A rs * y . Hence A pq * x .

在第二种情况下,令r为除初始状态和最终状态之外的状态,在该状态中,当对输入x进行计算时堆栈变空。那么从状态p到状态r以及从状态r到状态q的每部分计算最多包含k步。我们将y称为计算第一部分时读取的输入,将z称为计算第二部分时读取的输入。归纳假设意味着A pr *  yA rq *  z。由于产生式A pq A pr A rq属于G,因此A pq * x,这就完成了证明。

In the second case, let r be a state other than the initial and final state in which the stack becomes empty during the computation of input x . Then each of the parts of the computation from state p to state r and from state r to state q contains at most k steps. Let us call y the input read during the computation of the first part, and z the input read during the computation of the second part. By the induction hypothesis, it follows that A pr *  y and A rq *  z . Since the production A pq A pr A rq belongs to G , then A pq * x , which completes the proof.

这就完成了引理2.27和定理2.20的证明。

Together, this completes the proof of Lemma 2.27 and Theorem 2.20.

我们刚刚证明基于堆栈的自动机可以识别一类上下文无关语言。这个证明使我们能够确定正则语言和上下文无关语言之间的关系。由于每种正则语言都可以被某个有限自动机识别,并且每个有限自动机也是一个简单地忽略其堆栈的堆栈自动机,因此我们知道每种正则语言也是一种上下文无关语言。

We have just proved that pushdown automata recognize the class of context-free languages. This proof allows us to establish a correspondence between regular languages ​​and context-free languages. Since every regular language is recognized by some finite automaton, and every finite automaton is also a pushdown automaton that simply ignores its stack, we know that every regular language is also a context-free language.

结论 2.32

Motion 2.32

每种正则语言都是上下文无关语言。

Every regular language is a context-free language.

2.33

正则语言和上下文无关语言之间的关系

Figure 2.33

Relationships between regular and context-free languages

2.3

非上下文无关语言

2.3

Languages ​​that are not context-free

在本节中,我们提出了一种证明某些语言不是上下文无关的技术。回想一下,在 1.4 节中我们介绍了泵引理,它用于证明某些语言是不正则的。在这里,我们为上下文无关语言提出了一个类似的泵引理。他指出,每种上下文无关语言都被分配了一个称为泵送长度的特定值,这样该语言的所有较长单词都可以被“泵送”。然而,这一次“泵”的含义有点复杂。我们的意思是,一个单词可以分为五个部分,这样第二部分和第四部分可以一起重复任意多次,并且生成的单词仍然属于该语言。

In this section, we present a technique for proving that certain languages ​​are not context-free. Recall that in Section 1.4 we introduced the pumping lemma, which is used to prove that certain languages ​​are not regular. Here we present the analogous pumping lemma for context-free languages. It states that each context-free language has a special value, called the pumping length , such that all longer words of the language can be “pumped.” This time, however, the meaning of “pumping” is slightly more complex. By this we mean that a word can be split into five parts such that the second and fourth parts can be repeated together any number of times, and the resulting word will still belong to the language.

上下文无关语言的泵引理

Pumping Lemma for Context-Free Languages

定理2.34

Theorem 2.34

上下文无关语言的泵送定理

Pumping Theorem for Context-Free Languages

如果A是上下文无关语言,则存在一个数字p(泵长度),如果s是属于A的长度至少为p的任何单词,则s可以分为五个部分s = uvxyz,满足:

If A is a context-free language, there is a number p (pumping length) such that if s is any word of length at least p belonging to A , then s can be partitioned into five parts s = uvxyz , satisfying the conditions:

  1. 对于每个i ≥ 0,uvxyz A
  2. For every i ≥ 0, uv and xy and z A ,
  3. || > 0,
  4. | vy | > 0,
  5. | vxy | ≤ p
  6. | vxy | ≤ p .

当我们将单词s拆分为uvxyz时,条件 2 表示vy部分不能都是空词。否则,该定理就很容易得到满足。条件 3 表明vxy的内部部分总共的长度至多为p。这项技术要求有时有助于证明某些语言不是上下文无关的。

If we split a word s into uvxyz , condition 2 says that the parts v and y cannot both be empty words. Otherwise the theorem would be trivially satisfied. Condition 3 says that the interior parts v , x , and y together have length at most p . This technical requirement is sometimes useful in proving that certain languages ​​are not context-free.

证明的概念 A为 CFL 语言, G为生成该语言的 CFG 语法。我们需要证明任何属于A 的足够长的单词都可以被泵送并且仍然属于A。证明所依据的想法很简单。

Concept of the ProofLet A be a CFL language and let G be a CFG grammar generating this language. We need to show that any sufficiently long word belonging to A can be pumped and still belong to A . The idea on which the proof is based is simple.

s成为属于A 的一个很长的词。 (稍后我们将更精确地定义“非常长”的含义。)由于单词s属于A ,因此它可以从G派生,并且有一个解析树。s的解析树一定很高,因为s很长。因此,解析树必须包含从树根处的初始变量到叶子中的终结符号之一的一些长路径。在这条长路径上,由于鸽巢原理,变量R的某个符号必须重复。如下图所示,这种重复允许您用第一次出现R下方的子树替换第二次出现R下方的子树,并且仍然获得正确的解析树。因此,我们可以将s分成五个部分uvxyz,如图所示,并且我们可以重复第二和第四部分,获得仍然属于该语言的单词。换句话说,对于任何i ≥ 0,uv xyz都属于A。

Let s be a very long word belonging to A . (We will define more precisely what is meant by "very long" later.) Since the word s belongs to A , it can be derived from G and there is a parse tree for it. The parse tree for s must be very tall, since s is very long. So the parse tree must contain some long path from the initial variable in the root of the tree to one of the terminal symbols in the leaf. On this long path, some symbol for the variable R must be repeated because of the pigeonhole principle. As shown in the figure below, this repetition allows us to replace the subtree below the second occurrence of R with the subtree below the first occurrence of R and still obtain a valid parse tree. Thus, we can cut s into five parts uvxyz as indicated in the figure, and we can iterate over the second and fourth parts, obtaining a word that still belongs to the language. In other words, uv i xy i z belong to A for any i ≥ 0.

2.35

解剖树手术

Figure 2.35

Tree dissection surgery

现在让我们详细讨论以确保满足泵送引理的所有三个条件。我们还将向您展示如何计算泵送长度p

We now proceed to the details to ensure that all three conditions of the Pumping Lemma are satisfied. We will also show how to calculate the pumping length p .

证明 G是上下文无关语言A的 CFG 语法。令b为产生式右侧出现的最大符号数(我们假设至少为 2)。在任何使用此语法的解析树中,我们知道一个顶点最多可以有b个子节点。换句话说,至多b个叶子距离初始变量1步; b 2至多距初始变量2步;并且至多b h 个叶子距离初始变量有h步。因此,如果解析树的高度最多为h ,则该树生成的单词的长度最多bh。相反,如果生成的单词的长度至少为b h + 1,则其每个解析树的高度必须至少为h + 1。

Proof Let G be a CFG grammar for a context-free language A . Let b be the largest number of symbols that appear on the right-hand side of a production (assuming it is at least 2). In any parse tree using this grammar, we know that a vertex can have no more than b children. In other words, at most b leaves are 1 step away from the start variable; at most b 2 are 2 steps away from the start variable; and at most b h leaves are h steps away from the start variable. So if the height of a parse tree is at most h , the length of the word generated by it is at most b h . Conversely, if the generated word has length at least b h + 1, then each of its parse trees must have height at least h + 1.

让| V |将是语法G中变量的数量。我们选择泵浦长度p作为b |V|+1。现在,如果s是属于A的单词并且其长度等于或大于p,则其解析树的高度必须至少为 | V | + 1,因为b |V|+1b |V| + 1。

Let | V | be the number of variables in the grammar G . We choose p , the pumping length, to be b | V | + 1 . Now, if s is a word belonging to A and its length is equal to or greater than p , its parse tree must have height at least | V | + 1, since b | V | + 1b | V | + 1.

要了解如何泵送任何单词s,请令t成为其解析树之一。如果s有多个解析树,我们选择包含最少顶点数的解析树作为t 。我们知道t 的高度必须至少为 | V | + 1,所以从根到叶子的最长路径至少是 | V |+1。这样的路径至少包含 | V |+2 个顶点;一个是终端,其余的是变量。因此,这条路径至少包含| V | + 1 个变量。因为G只有| V |变量,某些R变量在此路径上出现多次。为了以后方便,我们选择R作为在较低的|之间重复的变量。V | + 这条路径上有 1 个变量。

To see how to pump any word s , let t be one of its parse trees. If s has multiple parse trees, we choose t to be the parse tree that contains the fewest vertices. We know that t must have height at least | V | + 1, so the longest path from the root to a leaf is at least | V |+1. Such a path contains at least | V |+2 vertices; one is a terminal, and the rest are variables. Thus, this path contains at least | V | + 1 variables. Since G has only | V | variables, some variable R appears on this path more than once. For later convenience, we choose R to be the variable that repeats among the lower | V | + 1 variables on this path.

我们将单词s分为uvxyz,如图 2.35 所示。对于R 的每次出现,该变量下方都有一个子树,生成单词s的一部分。R 的较高实例具有生成vxy的较大子树,而较低实例仅通过较小的子树生成x 。两个子树都是由同一个变量生成的,因此我们可以用一个子树替换另一个子树,仍然得到正确的解析树。重复用较大的子树替换较小的子树,会生成uv xyz形式的单词的解析树(对于所有i > 1)。用较小的子树替换较大的子树会生成单词uxz。这样,我们就达到了引理条件1的满足。现在我们将处理条件 2 和 3。

We divide the word s into uvxyz according to Figure 2.35. Each occurrence of R has a corresponding subtree below this variable, generating part of the word s . The higher occurrence of R has a larger subtree generating vxy , while the lower occurrence only generates x by the smaller subtree. Both subtrees are generated by the same variable, so we can substitute one for the other and still obtain a correct parse tree. Repeatedly replacing the smaller subtree with the larger one generates parse trees for words of the form uv and xy and z for all i > 1. Replacing the larger subtree with the smaller one generates the word uxz . We have thus satisfied condition 1 of the lemma. We now concern ourselves with conditions 2 and 3.

为了获得条件2,我们需要确保vy不都是空词ε。如果是的话,通过用较大的子树替换较小的子树获得的解析树将产生比t包含的顶点更少的顶点,并且仍然会生成s。这个结果是不可能的,因为我们已经选择t作为顶点数最少的s的解析树。这就是选择这种方式的原因。

To obtain Condition 2, we need to be sure that v and y are not both empty words of ε. If they were, the parse tree obtained by replacing the smaller subtree with a larger one would have fewer vertices than t contains , and would still generate s . This result is impossible, since we have already chosen t as the parse tree for s with the smallest number of vertices. This is precisely the reason for choosing t in this way.

为了获得条件3,我们需要确保vxy的长度最多为p。在s的解析树中,变量R的出现次数较高会生成vxy。我们选择R,以便两个出现都出现在下面的 | 中。V | + 1 个路径中的变量,并且我们选择了解析树中最长的路径,因此R生成vxy的子树的高度最多为 | V | + 1。这个高度的树最多可以生成b |V|+1 = p的字长。

To obtain Condition 3, we must be sure that the length of vxy is at most p . In the parse tree for s, the higher occurrence of R generates vxy . We have chosen R such that both occurrences are in the lower | V | + 1 variables in the path, and we have chosen the longest path in the parse tree, so the subtree in which R generates vxy has height at most | V | + 1. A tree of this height can generate a word of length at most b |V|+1 = p .

关于使用泵引理证明某些语言不是上下文无关的一些技巧可以在示例 1.73(第 80 页)之前的文本中找到,其中我们讨论了使用泵引理证明正则语言的非正则性的类似问题。

Some hints on using the pumping lemma to prove that some languages ​​are not context-free can be found in the text preceding Example 1.73 (page 80), where we discuss the similar problem of proving irregularity using the pumping lemma for regular languages.

2.36

Example 2.36

我们将使用泵引理来证明语言B = { a n b n c n : n ≥ 0} 不是上下文无关的。

We will use the pumping lemma to show that the language B = { a n b n c n : n ≥ 0} is not context-free.

我们假设B是CFL,这就产生了矛盾。令p为B 的泵浦长度,其存在由泵浦引理保证。我们选择单词s = a p b p c p。显然s属于B并且长度至少为p。泵浦引理指出s可以被泵浦,但我们将证明它不能。换句话说,我们将证明,无论我们如何将s划分为uvxyz,都会违反引理的三个条件之一。

We assume that B is a CFL language, and then we reach a contradiction. Let p be a pumping length for B , whose existence is guaranteed by the Pumping Lemma. We choose the word s = a p b p c p . It is clear that s belongs to B and has length at least p . The Pumping Lemma states that s can be pumped, but we will show that it cannot. In other words, we show that no matter how we partition s into uvxyz , one of the three conditions of the lemma will be violated.

首先,条件 2 规定单词vy中至少有一个非空。我们将考虑两种情况之一,具体取决于子词vy是否包含不止一种类型的字母符号。

First, condition 2 states that at least one of the words v or y is nonempty. We will consider one of two cases, depending on whether the subwords v and y contain more than one type of alphabetic symbol.

  1. vy都只包含一种类型的字母符号时,v不能同时包含a和 b,或者bc,这同样适用于单词y。在这种情况下,单词uv 2 xy 2 z不能包含相同的数字abc。因此,它不能属于语言B。这违反了引理的条件 1,因此是矛盾的。
  2. When both v and y contain only one type of symbol of the alphabet, v cannot contain both a and  b or both b and c , and the same is true for the word y . In such a case, the word uv 2 x y 2 z cannot contain equal numbers a , b , and c . Hence, it cannot belong to the language B . This violates condition 1 of the lemma and is therefore a contradiction.
  3. vy包含不止一种类型的符号时,uv 2 xy 2 z可能包含相等数量的三个字母符号,但顺序不正确。因此它不可能是语言B的成员,我们又遇到了矛盾。
  4. When either v or y contains more than one type of symbol, uv 2 xy 2 z may contain equal numbers of the three symbols of the alphabet, but not in the correct order. Hence it cannot be a member of the language B, and again we have a contradiction.

其中一种情况必定会发生。然而,既然两者都会导致矛盾,那么这个矛盾就不可避免。因此, B是 CFL的假设必定是错误的。这就是我们证明语言B不是 CFL 语言的方法。

One of these cases must occur. However, since both lead to a contradiction, the contradiction is inevitable. Therefore, the assumption that B is a CFL language must be false. We have thus proved that B is not a CFL language.

2.37

Example 2.37

C = { a i b j ck : 0 ≤ ijk }。我们将使用泵引理来证明C不是 CFL 语言。这种语言与例 2.36 中的语言B类似,但证明它不是上下文无关的有点复杂。

Let C = { a i b j c k : 0 ≤ ijk }. We use the pumping lemma to show that C is not a CFL. This language is similar to B in Example 2.36, but proving that it is not context-free is a bit more complex.

我们假设C是CFL,这会导致矛盾。令p为由泵浦引理得出的泵浦长度。我们将使用单词s = a p b p c p,就像以前一样,但这次我们必须“抽气”和“抽气”。令s = uvxyz并再次考虑例 2.36 中出现的两种情况。

We assume that C is a CFL, and we reach a contradiction. Let p be the pumping length, which follows from the Pumping Lemma. We use the word s = a p b p c p , as before, but this time we need to "pump down" as well as "pump up". Let s = uvxyz , and we again consider the two cases that occurred in Example 2.36.

  1. vy都只包含一种类型的字母符号时,v不包含字符a和 b,也不包含bc,单词y也是如此。请注意,先前用于情况 1 的推理不再适用,原因是C包含字符abc数量不等的单词,只要这些数量不减少。我们需要更仔细地分析情况,才能证明s字不能被夸大。请注意,由于vy各自包含一种类型的符号,因此符号abc之一不会出现在其中任何一个中。所以我们根据哪个符号不出现将这种情况分为三个子情况。
    1. 没有 a 符号。然后我们可以尝试抽真空以获取单词uv 0 xy 0 z = uxz。它包含单词s相同数量的 a 字符,但包含更少的b或更少的c。因此它不是C的元素,这产生了矛盾。
    2. 没有 b 符号。那么ac必须出现在vy中,因为两个子词都不能为空。如果存在a,则单词uv 2 xy 2 z包含的a多于b,因此不属于C。如果存在字符c,则单词uv 0 xy 0 z包含的b多于c,因此它不属于C。每种情况都存在矛盾。
    3. 没有 c 符号。那么单词uv 2 xy 2 z包含的字符ab多于c,因此它不属于C,存在矛盾。
  2. When both v and y contain only one type of symbol of the alphabet, v does not contain both the characters a and  b or both b and c , and the same is true for the word y . Note that the reasoning previously used for case 1 no longer applies. The reason is that C contains words with unequal numbers of the characters a , b , and c , unless these numbers decrease. We must analyze the situation more carefully to be able to show that the word s cannot be inflated. Note that since v and y contain only one type of symbol each, one of the symbols a , b , or c does not occur in either of them. We will therefore divide this case into three subcases according to which symbol does not occur.
    1. There are no a symbols . We can then try pumping down to get the word uv 0 xy 0 z = uxz . It contains the same number of a characters as the word s , but contains fewer b s or fewer c s . It is therefore not an element of C , which gives a contradiction.
    2. There are no symbols b . Then either a or c must appear in v or y , since neither of these substrings can be empty. If a occurs , the word uv 2 xy 2 z contains more a characters than b characters , and so does not belong to C . If c occurs , the word uv 0 xy 0 z contains more b characters than c characters, and so does not belong to C . In each case, a contradiction occurs.
    3. There are no symbols c . Then the word uv 2 xy 2 z contains more characters a or b than c , so it does not belong to C and a contradiction occurs.
  3. 如果vy包含不止一种类型的符号,则uv 2 xy 2 z将不包含按正确顺序排列的符号。因此,它不可能是元素C,我们就有了矛盾。
  4. If either v or y contains more than one kind of symbol, uv 2 xy 2 z will not contain the symbols in the correct order. Hence it cannot be an element of C and we have a contradiction.

因此,我们证明s不能被泵送,这违反了泵送引理,因此C不是上下文无关语言。

We have therefore shown that s cannot be pumped, which violates the Pumping Lemma, and so C is not a context-free language.

2.38

Example 2.38

D = { ww : w {0,1}*}。我们将使用泵浦引理来证明D不是 CFL。我们假设D是 CFL 语言,这会导致矛盾。令p为由泵浦引理得出的泵浦长度。

Let D = { ww : w {0,1}*}. We use the Pumping Lemma to show that D is not a CFL. We assume that D is a CFL language and achieve a contradiction. Let p be the pumping length by the Pumping Lemma.

这次s词的选择就不那么明显了。一种可能是单词0 p 10 p 1。它是D的一个元素,长度大于p,因此它似乎是一个很好的候选者。然而,如果我们如下划分,这个词可能会被夸大,所以它不适合我们的目的。

This time, the choice of word s is not so obvious. One possibility could be the word 0 p 10 p 1 . This is an element of D and has length greater than p , so it seems to be a good candidate. However, this word can be pumped if we split it as below, so it is not suitable for our purposes.

那么让我们尝试一下s词的另一个候选词。直观上,单词0 p 1 p 0 p 1 p似乎比之前的候选词更能捕捉到语言D的“本质”。事实上,我们可以证明这个词适合作为反例。

So let's try another candidate for the word s . Intuitively, the word 0 p 1 p 0 p 1 p seems to capture more of the "nature" of D than the previous candidate. In fact, we can show that this word is a suitable counterexample.

我们将证明单词s = 0 p 1 p 0 p 1 p不能被泵浦。这次我们将使用泵引理的条件 3 来限制单词s 的拆分方式。它指出我们可以通过除s = uvxyz来泵送s,其中 | vxy | ≤ p

We will show that the word s = 0 p 1 p 0 p 1 p cannot be pumped. This time we use condition 3 of the Pumping Lemma to restrict the way in which the word s can be partitioned . It states that we can pump s by partitioning s = uvxyz , where | vxy | ≤ p .

首先,我们将证明子词vxy必须包含单词s的中点。否则,如果该子词仅出现在s 的前半部分,则将s泵送到uv 2 xy 2 z会将1移动到后半部分的第一个位置,因此该词不能具有ww 的形式。类似地,如果vxy位于s 的后半部分 ,则将单词s泵入uv 2 xy 2 z会将0移动到前半部分的最后一个位置,因此它也不会具有ww 的形式。

First, we show that the subword vxy must include the midpoint of word s . Otherwise, if this subword occurred only in the first half of s , pumping s into uv 2 xy 2 z would move 1 to the first position of the second half, so this word could not have the form ww . Similarly, if vxy occurred in the second half  of s , pumping s into uv 2 xy 2 z would move 0 to the last position of the first half, so it also could not have the form ww .

然而,如果子词vxy覆盖了词s的中间,如果我们尝试将s泵送到uxz,它将是0 p 10 j 1 p,其中ij不能同时等于p。这个词没有上面的形式。由此可见,单词s不能被泵送,因此D不是 CFL 语言。

However, if the subword vxy encompasses the middle of a word s , if we try to pump s down to uxz , it will have the form 0 p 1 and 0 j 1 p , where i and j cannot both be equal to p . This word is not of the form ww . It follows that the word s cannot be pumped, and so D is not a CFL language.

2.4

确定性上下文无关语言

2.4

Deterministic Context-Free Languages

我们记得,确定性和非确定性有限自动机在语言识别能力方面是等效的。然而,非确定性堆叠自动机比确定性堆叠自动机更有效。我们将证明某些上下文无关语言无法被确定性 PDA 识别——这些语言需要非确定性 PDA。确定性下推自动机(DPDA)识别的语言称为确定性上下文无关语言(DCFL)。这个上下文无关语言的子类对于实际应用很重要,例如为编程语言编译器设计解析器,因为解析问题通常对于 DCFL 比 CFL 更容易。本节简要概述了这个重要而美丽的主题。

As we recall, deterministic and nondeterministic finite automata are equivalent in terms of language recognition power. However, nondeterministic pushdown automata are more powerful than their deterministic counterparts. We will show that some context-free languages ​​cannot be recognized by deterministic PDAs—these languages ​​require nondeterministic PDAs. Languages ​​that are recognized by deterministic pushdown automata (DPDAs) are called deterministic context-free languages ​​(DCFLs). This subclass of context-free languages ​​is important for practical applications, such as designing parsers for programming language compilers, because the parsing problem is generally easier for DCFLs than for CFLs. This section provides a brief overview of this important and beautiful topic.

在定义DPDA时,我们将坚持确定性的基本原则:在其计算的每一步中,DPDA根据其传递函数最多有一种方式进行。定义 DPDA 比定义 DFA 更复杂,因为 DPDA 可以读取输入符号而不从堆栈中弹出符号,反之亦然。因此,我们必须在 DPDA 传递函数中允许 ε 移动,即使 DFA 中禁止此类 ε 移动。这些 ε-转换采用两种可能的形式:ε-输入移动,对应于 δ( q , ε, x ) ,以及ε-堆栈移动,对应于 δ( q , a , ε) 。该运动可以结合两种形式,对应于δ( q ,ε,ε)。如果DPDA可以在特定情况下执行ε-转变,则禁止在涉及特定符号而不是ε的处理的相同情况下执行移动。否则,可能会出现多个有效的计算分支,从而导致不确定的行为。下面提供了正式的定义。

In defining DPDA we will stick to the basic principle of determinism: at each step of its computation, DPDA has at most one way to proceed according to its transition function. Defining DPDA is more complicated than defining DFA, since DPDA can read an input symbol without popping a symbol from the stack, and vice versa. As a result, we must allow ε-moves in the DPDA transition function, even though such ε-moves are forbidden in DFA. These ε-transitions take two possible forms: input ε-moves , corresponding to δ( q , ε, x ), and stack ε-moves , corresponding to δ( q , a , ε ). A move can combine both forms, corresponding to δ( q , ε, ε ). If DPDA can perform an ε-transition in a given situation, it is forbidden to perform a move in the same situation involving the processing of some symbol instead of ε. Otherwise, multiple valid computation branches could occur, leading to nondeterministic behavior. The formal definition is given below.

定义2.39

Definition 2.39

确定性堆叠自动机是一个有序的六元组 ( Q , Σ , Γ , δ, q 0 , F ),其中Q , Σ , ΓF是有限集,

A deterministic pushdown automaton is an ordered six ( Q , Σ , Γ , δ, q 0 , F ), where Q , Σ , Γ and F are finite sets, with

  1. Q是状态集,
  2. Q is a set of states,
  3. Σ是输入符号的字母表,
  4. Σ is the alphabet of input symbols,
  5. Γ是堆栈符号字母表,
  6. Γ is the alphabet of stack symbols,
  7. δ : Q × Σ ε × Γ ε ( Q × Γ ε ) { Ø } 是过渡函数,
  8. δ : Q × Σ ε × Γ ε ( Q × Γ ε ) { Ø } is a transition function,
  9. q 0 Q是初始状态,
  10. q 0 Q is the initial state,
  11. F Q是接受状态的集合。
  12. F Q is the set of accepting states.

传递函数δ必须满足以下条件。

The transition function δ must satisfy the following condition.

对于每个q Qa Σx Γ恰好是其中一个值

For every q Q , a Σ and x Γ exactly one of the values

δ( q , a , x ), δ( q , a , ε ), δ( q , ε , x ) 和 δ( q , ε , ε )

δ( q , a , x ), δ( q , a , ε), δ( q , ε, x ) and δ( q , ε, ε)

不是Ø

is not Ø .

转换函数可以返回 ( r , y )形式的单个移动,也可以通过返回Ø来指示没有动作。为了说明这些可能性,让我们考虑一个例子。假设具有传递函数 δ 的 DPDA M处于状态q,具有a作为下一个输入符号,符号x位于堆栈顶部。如果 δ( q , a , x ) = ( r , y ),则机器M将读取a,从堆栈中弹出x,进入状态r ,并将y压入堆栈。或者,如果 δ( q , a , x ) = Ø,则处于状态q的M没有读取a并从堆栈中弹出x的动作。在这种情况下,对函数 δ 施加的条件要求值 δ( q , a , ε) 、 δ( q , ε, x ) 或 δ( q , ε, ε ) 之一非空,然后M就会做出适当的动作。此条件通过防止 DPDA 在给定情况下采取两种不同的操作来强制执行确定性行为,如果 δ( q , a , x ) Ø且 δ( q , a , ε) Ø同时保持,就会发生这种情况。在堆栈不为空的每种情况下,DPDA 恰好包含一次允许的移动。如果堆栈为空,则仅当转换函数指定从堆栈中删除 ε 的移动时,DPDA 才能进行移动。否则,DPDA 不允许流量并丢弃输入字,而不读取其余数据。

A transition function can either return a single move of the form ( r , y ), or it can indicate no action by returning Ø . To illustrate these possibilities, consider an example. Suppose a DPDA M with a transition function δ is in state q , has a as its next input symbol, and has symbol x on top of its stack. If δ( q , a , x ) = ( r , y ), then M will read a , pop x off the stack, move to state r , and push y onto the stack. Alternatively, if δ( q , a , x ) = Ø , then M , being in state q , has no move that reads a and pops x off the stack. In this case, the condition imposed on the function δ requires that one of the values ​​δ( q , a , ε), δ( q , ε, x ), or δ( q , ε, ε) be nonempty, and then M will make the appropriate move. This condition enforces deterministic behavior, preventing DPDA from taking two different actions in a given situation, which would be the case if δ( q , a , x ) Ø and δ( q , a , ε) Ø . DPDA has exactly one legal move for each situation in which the stack is not empty. If the stack is empty, DPDA can make a move only if the transition function specifies a move that pops ε from the stack. Otherwise, DPDA has no legal move and discards the input without reading the rest of the data.

DPDA 中的验收工作方式与 PDA 类似。如果 DPDA 在读取输入字的最后一个符号后进入接受状态,则它接受该字。在所有其他情况下,这个词都会被删除。当 DPDA 读取了所有输入数据但在到达数据末尾时未能进入接受状态,或者当 DPDA 未能读取整个输入字时,就会发生这种情况。当 DPDA 尝试从空堆栈中弹出符号时,或者当 DPDA 进入无限的 ε 输入移动序列而不加载超过某个点的输入时,可能会发生后一种情况。

Acceptance in DPDA works analogously to PDA. If DPDA enters the accepting state after reading the last symbol from an input word, it accepts that word. In all other cases, the word is rejected. This occurs when DPDA reads all of the input data but fails to enter the accepting state after reaching the end of the data, or when DPDA fails to read the entire input word. The latter case can occur when DPDA tries to pop a symbol from an empty stack, or when DPDA enters an endless sequence of ε-input moves without reading any input data after a certain point.

DPDA识别的语言称为确定性上下文无关语言

The languages ​​recognized by DPDA are called deterministic context-free languages .

2.40

Example 2.40

示例 2.14 中的语言 { 0 n 1 n : n ≥ 0} 属于 DCFL 类。我们可以通过将缺失状态、输入符号和堆栈符号的任意组合添加到“死”状态(无法从“死”状态转移到接受状态)的转换,轻松地将其M 1堆栈机修改为 DPDA。

The language { 0 n 1 n : n ≥ 0} of Example 2.14 is of class DCFL. We can easily modify its stack automaton M 1 to be a DPDA by adding transitions for any combination of a missing state, an input symbol, and a symbol from the stack to a "dead" state from which it is not possible to transition to an accepting state.

例 2.16 和2.18显示了 CFL 语言 { a i b j ck : i , j , k ≥ 0 and j or i = k } 和 { ww R : w { 0 , 1 }*},其中不是 DCFL 语言。问题 2.57 和 2.58 表明非确定性对于识别这些语言是必要的。

Examples 2.16 and 2.18 show the CFL languages ​​{ a i b j c k : i , j , k ≥ 0 and j or i = k } and { ww R : w { 0 , 1 }*}, which are not DCFL languages. Problems 2.57 and 2.58 show that nondeterminism is necessary for recognizing these languages.

使用 DPDA 的论证本质上是相当技术性的,尽管我们非常努力地强调这些结构背后的基本概念,但读者可能会发现这一部分比前面章节的其他部分要求更高。本书后面的材料不依赖于本节的内容,因此可以省略。

The arguments using DPDA are quite technical in nature, and although we try hard to emphasize the basic concepts underlying these constructs, readers may find this section more demanding than other parts of the earlier chapters. The later material in this book is not dependent on the content of this section, so it can be omitted.

我们将从一个技术引理开始,这将简化后续的讨论。如前所述,如果 DPDA 无法读取整个输入字,它可以拒绝输入,但这样的 DPDA 很混乱。幸运的是,下一个引理表明我们可以将任何 DPDA 转换为始终读取整个输入的 DPDA。

We begin with a technical lemma that will simplify the further discussion. As mentioned, a DPDA can discard the input if it fails to read a complete input word, but such DPDAs introduce disorder. Fortunately, the next lemma shows that we can transform any DPDA into one that always reads the entire input.

引理2.41

Lemma 2.41

对于每个 DPDA,都有一个等效的 DPDA,它始终读取整个输入字。

For each DPDA there is an equivalent DPDA that always reads a complete input word.

证明概念 如果机器尝试从空堆栈中删除符号或者输入无限的输入 ε 移动序列,则 DPDA 可能无法读取整个输入字。我们将第一种情况称为暂停,将第二种情况称为循环。我们将通过使用特殊符号初始化堆栈来解决挂起问题。如果此符号随后在输入结束之前从堆栈中弹出,则 DPDA 会读取输入字直至末尾并将其丢弃。我们通过找到循环情况(即无法读取后来的输入符号的情况)来解决循环问题,并对 DPDA 重新编程以读取并丢弃剩余的输入数据而不是循环。

Proof Concept A DPDA may fail to read a complete input word if it tries to pop a symbol from an empty stack or if it enters an infinite sequence of ε-moves of the input. We will call the first situation a hang-up , and the second a loop-up . We solve the hang-up problem by initializing the stack with a special symbol. If that symbol is later popped off the stack before the end of the input is reached, the DPDA reads the input word to the end and discards it. We solve the loop-up problem by finding loop-up situations, situations in which no subsequent input symbol can ever be read, and reprogramming the DPDA so that instead of looping, it reads and discards the rest of the input.

我们需要调整这些修改,以解决输入的最后一个符号发生挂起或循环的情况。如果 DPDA 在读取最后一个符号后的任何时间进入接受状态,则修改后的 DPDA 将接受而不是拒绝输入字。

We need to adjust these modifications to account for the case where a hang or loop occurs on the last symbol of input data. If the DPDA enters the accepting state at any time after reading the last symbol, the modified DPDA will accept rather than reject the input word.

证明P = ( Q , Σ , Γ , δ, q 0 , F ) 为 DPDA。首先,我们将添加一个新的初始状态q start、一个附加的接受状态q accept、一个新的状态qreject以及其他新状态如下所述。我们对每个r ε Q a ε Σ εx y ε Γ ε进行以下更改。

Proof Let P = ( Q , Σ , Γ , δ, q 0 , F ) be a DPDA. First, we add a new initial state q start , an additional accepting state q accept , a new state q reject , and other new states as described below. We make the following modifications for every r Q , a Σ ε and x , y Γ ε .

首先,我们将修改P,以便一旦它进入接受状态,它就保持在某个接受状态,直到读取下一个输入符号。我们为每个q Q添加一个接受q a 的新状态。对于每个q Q,如果 δ( q , ε, x ) = ( r , y ),我们设置 δ( q a , ε, x ) = ( r a , y ),并且如果q F,我们也改变δ,使得 δ( q , ε , x ) = ( r a , y )。对于每个q Qa Γ,如果 δ( q , a , x ) = ( r , y ) ,我们设置 δ( q a , a , x ) = ( r , y ) 。令F ' 为新旧接受状态的集合。

First, we modify P so that after entering the accepting state, it remains in some accepting state until the next input symbol is read. We add a new accepting state q a for each q Q . For each q Q , if δ( q , ε, x ) = ( r , y ), we set δ( q a , ε, x ) = ( r a , y ), and if q F , we also change δ so that δ( q , ε, x ) = ( r a , y ). For each q Q and a Γ , if δ( q , a , x ) = ( r , y ), we set δ( q a , a , x ) = ( r , y ). Let F ' be the set of new and old accepting states.

然后,当尝试从空堆栈中删除符号时,我们将修改P以丢弃。为此,我们用一个特殊的新符号$初始化堆栈,如果P随后在非接受状态下检测到$ ,它将进入q拒绝状态并读取输入数据到底。如果P在接受状态下检测到$ ,则它转移到q接受状态。然后,如果还有未读的输入,则进入q拒绝状态并读取输入到底。形式上,我们设置 δ( q start , ε, ε) = ( q 0 , $ )。对于x Г且 δ( q , a , x ) Ø,如果q F ' 或a Σ,则我们设置 δ( q , a , $ ) = ( q拒绝, ε),并且如果q F 'a = ε,则我们设置 δ( q , a , $ ) = ( q Accept , ε)。对于a Σ,我们设置 δ( q拒绝, a , ε) = ( q拒绝, ε ) 和 δ( q接受, a , ε ) = ( q拒绝, ε ) 。

Next, we modify P so that it rejects when an attempt is made to pop a symbol from an empty stack. To do this, we initialize the stack with a special new symbol $ , and if P later detects $ while in the nonaccepting state, it enters the q reject state and reads the input to completion. If P detects $ while in the accepting state, it enters the q accept state . Then, if there is any unread input left, it enters the q reject state and reads the input to completion. Formally, we set δ( q start , ε, ε) = ( q 0 , $ ). For x Γ and δ( q , a , x ) Ø , if q F ' or a Σ , then we set δ( q , a , $ ) = ( q reject , ε), and if q F' and a = ε, then we set δ( q , a , $ ) = ( q accept , ε). For a Σ , we set δ( q reject , a , ε) = ( q reject , ε) and δ( q accept , a , ε) = ( q reject , ε).

最后,我们将修改P以丢弃而不是在到达输入末尾之前输入输入的无限 ε 移动序列。对于每个q ε Qx ε Γ,我们将调用 ( q , x )循环情况,如果当P在状态q下运行且符号x ε位于堆栈顶部时,它永远不会从堆栈中删除低于x的任何内容堆栈并且永远不会读取符号输入。如果P在后续的移动中进入接受状态,我们就说循环情况是接受,而在其他情况下是拒绝。如果 ( q , x ) 是接受循环情况,那么我们设置 δ( q , ε, x ) = ( q Accept , ε ),而如果 ( q , x ) 是拒绝循环情况,那么我们设置 δ( q , ε, x ) = ( q拒绝, ε)。

Finally, we modify P so that it discards rather than enters an infinite sequence of ε-moves of the input before reaching the end of the input. For each q Q and x Γ, we will call ( q , x ) a looping situation if, when P is started in state q with symbol x Γ at the top of the stack, it never pops anything below x and never reads an input symbol. We will say that a looping situation is accepting if P enters an accepting state in subsequent moves, and is rejecting otherwise . If ( q , x ) is an accepting looping situation, then we set δ( q , ε, x ) = ( q accept , ε), while if ( q , x ) is a rejecting looping situation, then we set δ( q , ε, x ) = ( q reject , ε).

为简单起见,我们假设从现在起 DPDA 将其输入加载到末尾。

For simplicity, we will from now on assume that DPDAs read their inputs to completion.

DCFL 语言的属性

DCFL Language Properties

现在我们将研究为什么 DCFL 类是封闭的和不是封闭的,然后使用这些知识来识别不是 DCFL 语言的 CFL 语言。

We will now examine with respect to what operations the class DCFL is and is not closed, and then use this knowledge to define a CFL language that is not a DCFL language.

定理2.42

Theorem 2.42

DCFL 类由于填充而关闭。

The class DCFL is closed with respect to complement.

证明的概念 在DFA中,交换接受和不接受状态会产生一个新的DFA,该DFA识别原始语言的补集,这证明了正则语言的类相对于补集是封闭的。除了一个问题之外,相同的方法也适用于 DPDA。即,DPDA 可以通过在输入字末尾的一系列移动中进入接受和不接受状态来接受其输入。在这种情况下,交换接受和不接受状态仍然会导致接受。

Proof Concept In DFA, swapping the accepting and nonaccepting states yields a new DFA that recognizes the complement of the original language, which proves that the class of regular languages ​​is closed under complement. The same approach works for DPDA, except for one problem. Namely, DPDA can accept its input by entering both accepting and nonaccepting states in a sequence of moves at the end of the input word. Swapping the accepting and nonaccepting states would still produce acceptance in such a case.

我们将通过修改 DPDA 来限制接受的情况来解决此问题。对于每个输入符号,修改后的DPDA只有在即将读取另一个符号时才能进入接受状态。换句话说,只有读取状态(始终读取输入符号的状态)才能成为接受状态。然后,通过仅交换那些阅读的接受和不接受,我们获得接受语言补语的 DPDA。

We solve this problem by modifying the DPDA to restrict the situations in which acceptance can occur. For each input symbol, the modified DPDA can only enter the accepting state if it is about to read another symbol. In other words, only the reading states—states that always read the input symbol—can be accepting states. Then, by interchanging acceptance and nonacceptance for only those reading states, we obtain a DPDA that accepts the complement of the language.

证明 首先,我们按照引理 2.41 的证明中所述修改P - 令 ( Q , Σ , Γ , δ , q 0 , F ) 为结果机。该机器始终读取整个输入字。而且,一旦进入接受状态,它就保持在接受状态,直到读取下一个输入符号。

Proof We first modify P as described in the proof of Lemma 2.41 – let ( Q , Σ , Γ , δ, q 0 , F ) be an output machine. This machine always reads a complete input word. Moreover, once it enters the accepting state, it remains in the accepting state until it reads another input symbol.

为了能够根据上述概念进行证明,我们需要识别阅读状态。如果处于状态q的 DPDA读取输入符号a Σ而不从堆栈中弹出任何内容,即 δ( q , a , ε) Ø,我们将q标记为读取状态。然而,如果这个状态同时在读取和从堆栈中弹出,则读取的决定可能取决于正在弹出的符号,因此我们需要将此步骤分为两部分:从堆栈中弹出,然后读取。因此,如果 δ( q , a , x ) = ( r , y ) 对于a Σx   Γ,那么我们添加一个新状态q x并修改 δ 使得 δ( q , ε, x ) = ( q x , ε) 和 δ( q x , a , ε ) = ( ry )。我们将状态q x标记为阅读状态。q x状态永远不会从堆栈中删除任何内容,因此它们的行为独立于堆栈的内容。我们将状态q x定义为接受 if q F。最后,我们从任何非读取状态的状态中删除接受状态的标记。修改后的 DPDA 相当于P,但在即将读取下一个符号时,对于每个输入符号最多进入一次接受状态。

To be able to prove the idea presented above, we need to identify the read states. If the DPDA in state q reads an input symbol a Σ without popping anything from the stack, i.e. δ( q , a , ε) Ø , we denote q as a read state. However, if this state reads and simultaneously pops, the decision to read may depend on the popped symbol, so we need to split this step into two: popping and then reading. Thus, if δ( q , a , x ) = ( r , y ) for a Σ and x   Γ , then we add a new state q x and modify δ so that δ( q , ε, x ) = ( q x , ε) and δ( q x , a , ε) = ( ry ). We designate state q x as the read state. States q x never pop anything from the stack, so their action is independent of the stack's contents. We designate state q x as the accepting state if q F . Finally, we remove the accepting state designation from any state that is not a read state. The modified DPDA is equivalent to P , but it enters the accepting state at most once for each input symbol, when it has to read the next symbol.

现在,在阅读状态中,我们用不接受状态替换接受状态,反之亦然。生成的 DPDA 可以识别互补语言。

Now among the reading states we change accepting states to non-accepting states and vice versa. The resulting DPDA recognizes the complementing language.

该定理暗示某些 CFL 语言不属于 DCFL 类。任何其补码不是 CFL 的 CFL 都不属于 DCFL 类。因此,A = { a i b j c k : i jj k,其中i , j , k ≥ 0} 是 CFL 语言,但不是 DCFL 语言。否则,A将是 CFL 语言,因此问题 2.18 的结果将错误地暗示A a * b * c * = { a n b n c n : n ≥ 0} 是上下文无关语言。

This theorem implies that some CFL languages ​​are not DCFL languages. Any CFL language whose complement is not a CFL language is not a DCFL language. Thus, A = { a i b j c k : i j or j k , where i , j , k ≥ 0} is a CFL language but not a DCFL language. Otherwise, A would be a CFL language, so the result of Problem 2.18 would incorrectly imply that A a * b * c * = { a n b n c n : n ≥ 0} is a context-free language.

在问题 2.53 中,有必要证明 DCFL 语言的类对于其他众所周知的操作(例如并集、交集、克林闭包或顺序反转)不是封闭的。

In Problem 2.53 it is necessary to show that the class of DCFL languages ​​is not closed under other well-known operations such as union, intersection, Kleene closure, and order inversion.

为了简化考虑,我们偶尔会包含结束标签输入,其中一个特殊的结束标签⊣被附加到输入单词的末尾。在这种情况下,我们将添加到 DPDA 输入字母表中。正如我们将在下一个定理中展示的那样,添加结束标记不会改变 DPDA 机器的计算能力。然而,为标记输入进行 DPDA 编程通常更容易,因为我们可以利用知道输入单词何时结束的优势。对于任何语言A,我们将把带有结束标记A 的语言 写为单词集合w ,其中w A。

To simplify matters, we will occasionally consider end-tag inputs , in which a special end-tag ⊣ is appended to the end of the input word . In such cases, we add to the input alphabet of the DPDA. As we will show in the next theorem, adding end-tags does not change the computational power of DPDAs. Nevertheless, programming DPDAs for tagged inputs is often easier, since we can exploit the fact that we know when the input word ends. For any language A, we will write the end-tag language A as the set of words w , where w A .

定理2.43

Theorem 2.43

语言A属于 DCFL 类当且仅当A 是 DCFL 语言。

A language A is of class DCFL if and only if A is a DCFL language.

证明的概念 直接证明该定理是正则的。让我们假设一些 DPDA P识别A。然后 DPDA P'识别A ,模拟P直到P'读取。此时,如果P已与前一个符号一起进入接受状态,则P'接受。 P'不读取之后的任何符号。

Concept of ProofThe direct proof of this theorem is routine. Suppose some DPDA P recognizes A . Then DPDA P' recognizes A , simulating P until P' reads . At that point P' accepts, provided P entered the accepting state with the previous symbol. P' does not read any symbols after .

为了证明相反的方向,我们假设 DPDA P识别A 并构造一个识别A的 DPDA P'。当读取输入单词时,P' 模拟 P 的动作。在读取下一个输入符号之前,P'确定如果该符号为⊣ , P是否会接受输入。如果是,P'进入接受状态。请注意,P在读取后可以对堆栈进行操作,因此读取后是否接受可能取决于堆栈的内容。当然,P'无法为每个输入符号弹出整个堆栈,因此它必须确定P在读取后将做什么,但不从堆栈中弹出任何内容。相反,P'在堆栈上存储附加信息,使其能够随时确定P是否会接受。该信息指示 P在(可能)操作堆栈时最终可以接受哪些状态,但无需读取进一步的输入。

To prove the opposite, we assume that DPDA P recognizes A and construct DPDA P' that recognizes A . As input is read, P' simulates the action of P. Before reading the next input symbol, P' determines whether P would accept the input if that symbol were . If so, P' enters an accepting state. Note that after reading ⊣ , P can perform operations on the stack, so determining whether it will accept after reading may depend on the stack's contents. Of course, P' cannot pop the entire stack on every input symbol, so it must determine what P will do after reading , but without popping anything from the stack. Instead, P' stores additional information on the stack that allows it to determine at any time whether P would accept. This information indicates from which states  P can eventually accept, while (potentially) manipulating the stack but without reading any further input.

证明 我们将只提供从右到左方向的证明细节。如证明概念中所述,令 DPDA P = ( Q , Σ { }, Γ , δ, q 0 , F ) 识别语言A ;在此基础上,我们将构造一个识别A的 DPDA P' = ( Q' , Σ , Γ ' , δ', q 0 ' , F' )。首先,我们将修改P,以便在每次移动中恰好执行以下操作之一:读取输入符号;将符号放入堆栈;从堆栈中删除一个符号。执行这些修改很简单,并且涉及引入新状态。

Proof We present the details of the proof only for the right-to-left direction. As described in the concept of the proof, let DPDA P = ( Q , Σ { }, Γ , δ, q 0 , F ) recognizes the language A ; from it we construct DPDA P' = ( Q' , Σ , Γ ' , δ', q 0 ' , F' ) recognizes A . We first modify P so that each move performs exactly one of the following operations: reading an input symbol; pushing a symbol onto the stack; popping a symbol from the stack. These modifications are straightforward to implement and consist in introducing new states.

P'通过维护散布有附加信息的堆栈内容的副本来模拟P。每次P '将符号之一从P 的堆栈推入堆栈时,P'就会将表示P的状态子集的符号推入堆栈。因此我们定义Г ' = Г P ( Q )。P'堆栈将Γ元素与P ( Q )元素交错。如果R P ( Q ) 是堆栈顶部的符号,那么如果我们在属于R的任何状态下运行P,那么P最终将接受输入,而无需读取其他输入符号。

P' simulates P by keeping a copy of the contents of its stack interspersed with additional information. Whenever P' pushes one of the symbols from the stack of P , P' then pushes a symbol representing a subset of the states of P . We thus define Γ ' = Γ P ( Q ). The stack of P' intersperses the elements of Γ with the elements of P ( Q ). If R P ( Q ) is the symbol at the top of the stack, then if we run P in any of the states belonging to R , then P will eventually accept input without reading any additional input symbols.

最初,P'将集合R 0压入堆栈,其中R 0包含每个状态q,这样如果P以空堆栈开始状态q,它最终将接受而不读取输入符号。然后P'开始模拟P。为了模拟堆栈中的移动,P'首先弹出位于顶部的状态集(忽略它),然后弹出P在该移动中将采用的符号,然后使用它来确定P 的下一个移动。推移 δ( q , ε, ε) = ( r , x ) 的模拟如下,其中Px同时从状态q移动到状态r 。首先,P'检查其堆栈顶部的状态集R ,然后将x放入堆栈,然后将集合S放入堆栈中,使得q S,当q F或当 δ( q , ε, x ) = ( r , ε ) 且r R。换句话说,S是一组状态,这些状态要么直接接受自身,要么在x从堆栈中删除后导致属于R的状态。读取流量模拟 δ( q , a , ε) = ( r , ε) 以这样的方式进行:P'检查堆栈顶部的集合R ,如果r R ,则移动到接受状态。如果此时P'位于输入单词的末尾,则它接受。如果这不是输入结束,则继续模拟P ,因此这个接受状态也必须记录机器P的状态。因此,我们创建这个状态作为P原始状态的第二个副本,将其标记为P'中的接受状态。

Initially, P' pushes onto the stack a set R 0 , where R 0 contains each state q such that if P starts in state q with an empty stack, it will eventually accept without reading any input symbols. P' then begins to simulate P . To simulate a popping move, P' first pops the set of states that was at the top (ignoring it), then pops again the symbol that P would have popped on that move, and then uses it to determine P ' s next move . The simulation of a pushing move δ( q , ε, ε) = ( r , x ), in which P pushes x when transitioning from state q to state r , is done as follows. First, P' examines the set of states R at the top of its stack, then pushes x onto the stack , and then the set S , such that q S , whenever q F or whenever δ( q , ε, x ) = ( r , ε) and r R . In other words, S is the set of states that either accept directly or lead to a state in R after x is popped from the stack. The simulation of the read move δ( q , a , ε) = ( r , ε) proceeds in such a way that P' examines the set R at the top of the stack and moves to an accepting state if r R . If P' is at the end of the input word at this point, it accepts. If this is not yet the end of the input, it continues the simulation of P , so this accepting state must also record the state of P . So we create this state as a second copy of the original state from P , marking it as an accepting state in P' .

确定性上下文无关语法

Deterministic Context-Free Grammars

在本节中,我们定义与确定性堆叠自动机相对应的确定性上下文无关语法。我们将证明这两个模型在表达能力方面是等效的,只要我们将自己限制在带有结束标记的语言中,其中所有单词都以符号结尾。因此,这种对应关系并不像在正则表达式和有限自动机,或者上下文无关语法和堆叠自动机的情况下观察到的那么强,其中生成和识别模型描述完备相同的一类语言,而不需要结束标签。然而,对于 DPDA 和 DCFG,标签是必要的,否则将无法保持等效性。

In this section, we define deterministic context-free grammars that correspond to deterministic pushdown automata. We show that these two models are equivalent in expressive power, provided that we restrict ourselves to languages ​​with end tags, where all words end with the symbol . This correspondence is therefore not as strong as that observed for regular expressions and finite automata, or for context-free grammars and pushdown automata, where the generating and recognizing models describe exactly the same class of languages ​​without the need for end tags. However, in the case of DPDA and DCFG, the tags are necessary, since otherwise the equivalence does not hold.

在确定性自动机中,计算的每一步都决定下一步。机器无法选择如何操作,因为每个点都只有一种可能性。为了定义语法中的确定性,可以看出自动机中的计算对应于语法中的推导。正如我们将看到的,在确定性语法中,推导是有限的。

In a deterministic automaton, each computational step determines the next step. The automaton cannot choose how to act, since at each point there is only one possibility. To define determinism in grammar, we can note that computations in automata correspond to derivations in grammars. As we will see, in deterministic grammars the derivations are restricted.

CFG 语法中的推导从种子变量开始,并通过与语法产生式一致的一系列替换自上而下进行,直到推导形成终端词。为了定义 DCFG 语法,我们将采用自下而上的方法,从终结符本身的单词开始并反向推导,使用一系列归约步骤,直到到达种子变量。每个归约步骤都是反向替换,其中产生式右侧的终结符和变量的字被相应左侧的变量替换。被替换的词称为缩减词。整个逆推导过程称为约简。确定性 CFG 语法是通过具有特定属性的约简来定义的。

Derivations in CFG grammars start with an initial variable and proceed "top-down" through a series of substitutions compatible with the grammar's productions until the derivation produces a terminal word. To define DCFG grammars, we take a "bottom-up" approach, starting with the terminal word itself and performing the derivation in reverse order, using a series of reduction steps until we reach the initial variable. Each reduction step is a reverse substitution in which the terminal word and variables on the right-hand side of the production are replaced by the variable on the corresponding left-hand side. The word being replaced is called the reducing word . The entire reverse derivation is called a reduction . Deterministic CFG grammars are defined by reductions that have a certain property.

更正式地说,如果u和 v是变量和终结词,那么我们写↣  v来表示v可以在单个归约步骤中从u获得。换句话说,u   v与v u的含义相同。zu 到 v的约简称为序列

More formally, if u and  v are words of variables and terminals, then we write ↣  v to express that v can be obtained from u in a single reduction step. In other words, u   v is the same as v u . A reduction from to v is called the sequence

u = u 1 u 2 u k = v

u = u 1 u 2 u k = v

我们说u可约简为 v,我们将其写为u * v。因此,每当v * u时, u * vu的减少是u到初始变量的减少。在左侧归约中,每个归约词仅在归约完备位于其左侧的所有其他归约词之后才被归约。思考片刻后,您会发现左侧减少与右侧减少相反。

and we say that u is reducible to v , which we write as u * v . Thus, u * v , whenever v * u . A reduction from u is a reduction from u to the initial variable. In the case of left reduction, each reducing term is reduced only after reducing all other reducing terms that are entirely to the left of it. Upon reflection, one can see that left reduction is the inverse of the right derivation.

这就是 CFG 文法决定论背后的思想。对于具有初始变量S和属于其语言的单词w 的CFG 文法,我们称w 的左约简为

This is the idea underlying the determinism of CFG grammars. For a CFG grammar with an initial variable S and a word w of its language, we say that the left reduction of w is

w = u 1 u 2 u k = S

w = u 1 u 2 u k = S .

首先,我们要求每个u i确定下一个约简步骤,因此u i +1。所以w决定了整个左侧约简。该要求仅要求语法明确。为了实现决定论,我们必须走得更远。对于每个u i ,下一个归约步骤必须由前缀u i唯一确定,直到并包括该归约步骤的归约字h 。换句话说, u i中的左侧归约步骤不依赖于归约字右侧的符号。

First, we require that each u i determines the next reduction step, and thus u i +1 . So w determines the entire left-hand reduction. This requirement entails only that the grammar be unambiguous. To obtain determinism, we need to go further. For each u i , the next reduction step must be uniquely determined by the prefix u i up to and including the reducing word h for that reduction step. In other words, the left-hand reduction step in u i does not depend on the symbols to the right of the reducing word.

引入适当的术语应该有助于澄清这个概念。令w为由 CFG 语法G生成的语言中的单词,并令u出现在单词w的左侧约简中。让产生式T h用于归约步骤u i u i +1。这意味着我们可以写u i = xhyu i +1 = xTy,其中h是缩减词,x是u i到h左侧的部分,y是u i到 h 右侧的部分。H。这可以表述如下。

Introducing appropriate terminology should help to clarify this concept. Let w be a word from the language generated by the CFG grammar G and let u i occur in a left reduction of w . Let the reduction step u i u i +1 use the production T h . This means that we can write u i = xhy and u i +1 = xTy , where h is the reducing word, x is the part of u i to the left of h , and y is the part of u i to the right of h . This can be represented as follows.

2.44 xhy xTy

的展开图

Figure 2.44

Expanded view of xhy xTy

单词h,包括产生式T h 称为句柄 ui。换句话说,出现ε L ( G )的左侧约简中的单词u i的句柄是约简单词在u i中的出现以及该约简中u i 的约简产生式。有时,当我们对减少生产不感兴趣时​​,我们会使用术语句柄来指代减少词本身。出现在属于L ( G )的某个单词的左侧约简中的单词被称为正确单词。我们仅为有效单词定义句柄。

A word h , together with the production T h , is called a handle u i . In other words, the handle of a word u i , appearing in a left reduction of w L ( G ), is the occurrence of the reducing word in u i together with the reducing production for u i in that reduction. Sometimes, when we are not interested in the reducing production, we will use the term handle to refer to the reducing word itself. A word that appears in the left reduction of some word belonging to L ( G ) is called a valid word. We define handles only for valid words.

一个有效的单词可以有多个句柄,但前提是语法不明确。独特的语法只能通过单个解析树生成单词,因此左归约以及它们的句柄也是唯一指定的。

A valid word can have multiple handles, but only if the grammar is ambiguous. Unambiguous grammars can generate words only by a single parse tree, and thus also left reductions, and with them handles, are uniquely defined.

请注意,y是u i中句柄后面的部分,始终仅由终结符组成,因为归约是在左侧。否则,y可以包含变量符号,并且它只能来自较早的归约步骤,其归约字完备位于h的右侧。然而,那么左侧减少应该已经减少了前面步骤中的手柄。

Note that y , the part of u i following the handle, always consists of terminals only, since the reduction is left-handed. Otherwise, y could contain a variable symbol, and this could only come from an earlier reduction step whose reduction word was entirely to the right of h . However, then the left-handed reduction should have reduced the handle in the earlier step.

2.45

Example 2.45

考虑语法G 1

Consider the grammar G 1 :

R S |时间

R S | T

S a S b | ab

S a S b | ab

T a T bb |艾布

T a T bb | abb

该文法的语言是B C,其中B = { a m b m : m ≥ 1},并且C = { a m b 2 m | m≥1 }。在下面单词aaabbb L ( G 1 )的左侧约简中,我们在每一步中都强调了句柄:

The language of this grammar is B C , where B = { a m b m : m ≥ 1}, and C = { a m b 2 m | m ≥ 1}. In the following left reduction of the word aaabbb L ( G 1 ) we emphasize the handle at each step:

aa ab bb a aSb b aSb S R

aa ab bb a aSb b aSb S R .

同样,单词aaabbbbbb的左缩减如下所示:

Similarly, the left reduction of the word aaabbbbbb is shown below :

aa abb bbbb a aTbb bb aTbb T R

aa abb bbbb a aTbb bb aTbb T R .

在这两种情况下,所示的左侧缩减是唯一可能的缩减;然而,在其他可能出现多种潜在约简的语法中,我们必须使用左约简来定义句柄。请注意,句柄aaabbbaaabbbbbb并不相等,即使这些单词的开头部分是匹配的。我们将在稍后定义 DCFG 语法时更详细地讨论这个问题。

In both cases, it so happens that the left reductions shown are the only possible reductions; however, in other grammars, where multiple potential reductions can occur, we must use left reductions to define handles. Notice that the handles aaabbb and aaabbbbbb are not equal, even though the initial parts of these words match. We will discuss this issue in more detail later, when we define DCFG grammars.

PDA可以通过使用不确定性来猜测输入属于B还是C来识别L ( G 1 )。然后,将所有a放入堆栈后,将它们一一删除并分别与bbb进行匹配。在问题 2.55 中,需要证明L ( G 1 ) 不属于 DCFL 类。如果我们尝试构建一个识别这种语言的 DPDA,我们会发现机器无法提前知道输入属于B还是C,因此它不知道如何将ab匹配。让我们将此语法与G 2语法进行比较:

A PDA can recognize L ( G 1 ) by using nondeterminism to guess whether the input belongs to B or C . Then, after pushing all the a 's onto the stack , it pops them off one by one and matches each one with b or bb , as appropriate . In Problem 2.55, we will have to show that L ( G 1 ) is not of class DCFL. If we try to build a DPDA that recognizes this language, we will notice that the machine has no way of knowing in advance whether the input belongs to B or C , and so it has no way of matching a to b . Let's compare this grammar with the grammar G 2 :

R 1 S | 2T

R 1 S | 2 T

S a S b | ab

S a S b | ab

T a T bb |艾布

T a T bb | abb

其中第一个输入符号包含此信息。因此,我们对 DCFG 语法的定义必须包括G 2但不包括G 1

where the first symbol of the input contains this information. So our definition of DCFG grammars must include G 2 but exclude G 1 .

2.46

Example 2.46

G 3为以下语法:

Let G 3 be the following grammar:

S T

S T

T T ( T ) | ε

T T ( T ) | ε

这个语法说明了几点。首先,它生成带有标签的语言。稍后当我们证明 DPDA 和 DCFG 之间的等价性时,我们将重点讨论此类语言。其次,归约可能包含 ε 句柄,这由单词()() 左侧归约中的短下划线表示:

This grammar illustrates several points. First, it generates a tagged language. We will focus on such languages ​​later when we prove the equivalence between DPDA and DCFG. Second, reductions can have ε-handles, as indicated by the short underscores in the left reduction of the word ()() :

()() T () () T ( T ) () T () T ( T ) T S

()() T () () T ( T ) () T () T ( T ) T S .

句柄在定义 DCFG 语法中起着重要作用,因为它们决定约简。一旦我们知道了单词句柄,我们就知道了下一步的缩减步骤。为了理解正在构建的定义,我们必须牢记我们的目标:我们想要定义 DCFG 语法以对应于 DPDA。我们将通过展示如何将 DCFG 转换为等效的 DPDA 来确保这种对应关系,反之亦然。为了使此转换起作用,DPDA 必须找到句柄,以便找到归约。然而,找到把手可能并不容易。似乎需要知道下一个约简步骤才能确定给定单词的适当句柄,但 DPDA 并不先验地知道下一个约简步骤。我们将通过限制 DCFG 中的句柄来解决这个问题,以便 DPDA 可以轻松找到它们。

Handles play an important role in defining DCFG grammars, since they determine reductions. Once we know the handle of a word, we know the next reduction step. To understand the definition we are constructing, we need to keep in mind our goal: we want to define DCFG grammars so that they correspond to DPDAs. We will ensure this correspondence by showing how to transform a DCFG into an equivalent DPDA, and vice versa. For this conversion to work, the DPDA must find handles so that it can find reductions. However, finding handles may not be easy. It seems that knowing the next reduction step is necessary to be able to determine the appropriate handle for a given word, but DPDAs do not know the next reduction steps a priori. We solve this problem by restricting the handles in the DCFG so that DPDAs can easily find them.

为了证明我们的定义的合理性,请考虑歧义语法,其中某些单词具有多个句柄。选择正确的句柄可能需要预测哪个解析树输出哪个单词,而 DPDA 肯定无法获得这些信息。正如我们将看到的,DCFG 语法是明确的,因此句柄是唯一的。然而,仅唯一性不足以定义 DCFG 语法,如示例 2.45 中的G 1语法所示。

To justify our definition, consider ambiguous grammars in which some words have multiple handles. Choosing the appropriate handle may require predicting which parse tree outputs a given word, information that is certainly not available to DPDA. As we will see, DCFG grammars are unambiguous, so handles are unique. However, uniqueness alone is not sufficient to define a DCFG grammar, as the grammar G 1 of Example 2.45 shows.

为什么句柄是唯一的这一事实并不意味着我们正在处理 DCFG?当我们检查G 1语法中的句柄时,答案就显而易见了。如果w B,则句柄为ab,但如果w C,则句柄为abb。虽然w确定发生哪种情况,但确定句柄是ab还是abb可能需要检查整个单词w,并且 DPDA 在必须选择句柄时还不知道整个输入。

Why doesn't the fact that handles are unique imply that this is a DCFG? The answer becomes obvious when we examine the handles in the grammar G 1 . If w B , then the handle is ab , but if w C , then the handle is abb . Although w determines which case is which, determining whether the handle is ab or abb may require examining the entire word w , and the DPDA does not yet know the entire input when it has to choose a handle.

为了能够定义与DPDA对应的DCFG语法,我们需要对句柄提出更强的要求。正确单词的开头,直到句柄的末尾,必须足以确定句柄是什么。因此,如果我们从左到右读取正确的单词,我们一读到它就必须知道我们有一个句柄。我们不需要阅读超出这一点来识别句柄。回想一下,有效字的未读部分仅包含终结符,因为该字是通过仅终结符的输入字左约化形成的,并且未读部分尚未被处理。因此,如果h是每个有效单词xhŷ中的唯一句柄,则我们可以说有效单词v = xhy的句柄h强制句柄,其中ŷ Σ *。

In order to define a DCFG grammar corresponding to DPDA, we need to impose stronger requirements on handles. The beginning of a valid word, up to the end of the handle, must be sufficient to determine what the handle is. Thus, if we read a valid word from left to right, we need to know that we have a handle as soon as we read it. We do not need to read beyond that point to be able to identify the handle. Recall that the unread part of a valid word contains only terminals, since the word is formed by left reduction of the input word of terminals themselves, and the unread part has not yet been processed. We can therefore say that a handle h of a valid word v = xhy is a forced handle , if h is a unique handle in every valid word xhŷ , where ŷ Σ *.

定义2.47

Definition 2.47

确定性上下文无关语法是一种上下文无关语法,其中每个有效单词都有一个强制句柄。

A deterministic context-free grammar is a context-free grammar in which every valid word has a forced handle.

为了简单起见,我们将在本章的其余部分假设 CFG 种子变量不会出现在任何产生式的右侧,并且每个语法变量出现在该语法生成​​的语言的某些单词的约简中,即,语法不包含冗余变量。

For simplicity we will assume in the rest of this chapter that the initial variable CFG does not appear on the right-hand side of any production and that each variable of the grammar appears in the reduction of some words of the language generated by the grammar, i.e. that the grammar contains no redundant variables.

尽管我们对 DCFG 语法的定义在数学上是精确的,但它并没有提供一种简单的方法来确定给定的 CFG 语法是否是确定性的。我们现在将展示一个执行此操作的过程,称为DK测试。当我们展示如何将 DCFG 语法转换为 DPDA 时,我们还将使用 DK 测试底层的构造来进行 DPDA 句柄检索。

Although our definition of DCFG grammars is mathematically precise, it does not provide a simple way to determine whether a given CFG grammar is deterministic. We now show a procedure that does just this, called the DK test . We will also use the construction that underlies the DK test to find handles via DPDA when we show how to transform DCFG grammars into DPDAs.

DK 测试依赖于一个简单但令人惊讶的事实。对于任何 CFG G语法,我们可以构造一个关联的确定性DK有限机器识别句柄。特别是,DK机器接受来自的输入,如果

The DK test relies on a simple, yet surprising fact. For any CFG grammar G , we can construct an associated deterministic finite automaton DK identifying handles. In particular, the DK accepts its input from , if

  1. z是某个有效单词的前缀v = zy
  2. z is a prefix of some valid word v = zy ,
  3. z以句柄v结束。
  4. z ends with the handle v .

此外,每个接受DK状态都指示相关的减少生产(或多个生产)。对于一般的 CFG 语法,可以根据v扩展z 的有效词来应用多重归约产生式。然而,正如我们将看到的,在 DCFG 语法中,每个接受状态恰好对应于一个减少产生式。

Moreover, each accepting state of DK indicates an associated reduction production (or productions). In the case of a general CFG grammar, multiple reduction productions may apply, depending on which valid word v extends z . However, as we shall see, in DCFG grammars each accepting state corresponds to exactly one reduction production.

DK测试将在DK机器正式推出并确定其属性后讨论,但计划如下。在 DCFG 语法中,所有句柄都是强制的。因此,如果zy是一个带有前缀z且以单词zy的句柄结尾的有效单词,则该句柄是唯一的,并且它也是所有有效单词的句柄。为了满足这些属性,每个DK接受状态必须与单个句柄相关联,从而与单个可操作的归约生成相关联。此外,在读取属于Σ *的字之后,接受状态不能具有到接受状态的传出路径。否则,句柄zy将不是唯一的或将依赖于y。在DK测试中,我们将构造一个DK自动机,然后如果该自动机的所有接受状态都具有这些属性,则称G是确定性的。

The DK Test will be discussed after the DK automaton has been formally introduced and its properties stated, but the plan is as follows. In the DCFG grammar, all handles are coerced. Thus, if zy is a valid word with prefix z that ends in a handle for the word zy , then this handle is unique and it is also a handle for all valid words . For these properties to hold, each of the accepting states of the DK must be associated with a single handle, and hence with a single, applicable reducing production. Furthermore, an accepting state cannot have an outgoing path to the accepting state after reading a word belonging to Σ *. Otherwise, the handle zy would either not be unique or would be dependent on y . In the DK Test, we construct a DK automaton and then claim that G is deterministic if all of its accepting states have these properties.

为了构造 DFA DK,我们构造等效的 NFA K,然后通过定理 1.39 中引入的子集构造将K变换为DK 1 。为了理解机器K,让我们首先考虑 NFA J执行一个更简单的任务。它接受以任何产生式右侧结尾的任何输入单词。构造J很容易。它猜测要使用哪个产生式,并且还猜测开始将输入与该产生式右侧匹配的点。当他调整输入时,J通过所选的右侧跟踪他的进度。我们可以通过在适当的生产点放置一个点来表示这一进展,这就是“点生产”,在该主题的其他一些研究中也称为这种情况。因此,对于右侧有k 个符号的每个产生式B u 1 u 2 …u k ,我们获得k + 1 种情况:

To construct the DFA DK , we construct an equivalent NFA K , and then transform K into DK 1 via the subset construction introduced in Theorem 1.39. To understand the automaton K , first consider an NFA J performing a simpler task. It accepts any input word that ends with the right-hand side of any production. Constructing J is easy. It guesses which production to use, and also guesses the point at which to start matching the input to the right-hand side of that production. As it matches the input, J tracks its progress through the chosen right-hand side. We can represent this progress by placing a dot in the appropriate place in the production, which gives us a “dotted production,” also called a situation in some other treatises on the subject. Thus, for each production B u 1 u 2 …u k with k symbols on the right-hand side, we obtain k + 1 situations:

这些情况中的每一种都对应于机器J的一种状态。我们将用B uv周围的框来标记与情况B uv相关的状态。接受B u 的状态对应于末尾带有点的完整产生式。我们为所有符号添加一个单独的初始状态和一个反馈循环,并为每个产生式B u添加一个到B .u 的ε 转换。因此,如果输入末尾匹配成功,则J接受。如果出现不匹配或者匹配结束没有与输入数据结束同时出现,则J机的这条计算路径被丢弃。

Each of these situations corresponds to one state of the automaton J . We will denote the state associated with the situation B uv by a box around B uv . The states accepting B u. correspond to completed productions in which the dot is at the end. We add a separate initial state with a loopback for all symbols and an ε-transition to B .u for each production B u . Thus J accepts if the match is successfully completed at the end of the input. If there is a mismatch or the end of the match does not occur simultaneously with the end of the input, this path of computation of the automaton J is discarded.

NFA K 的工作原理类似,但在选择匹配产品时更加谨慎。仅允许可能减少产量。与J一样,它的状态对应于所有情况。它包含一个特殊的初始状态,对于与初始变量S 1相关的每个产生式,具有到S 1 .u的 ε 转换。在其计算的每个分支中,K将潜在的归约输出与输入的子字相匹配。如果这个产生式的右侧包含一个变量,K可以非确定性地切换到某个产生该变量的产生式。这个概念由引理 2.48 形式化。但首先,我们将详细描述机器K。

The NFA K works similarly, but is more judicious in choosing the productions to match. Only potentially reducing productions are allowed. As in J , its states correspond to all situations. It contains a special initial state with an ε-transition to S 1 .u for each production involving the initial variable S 1 . In each branch of its computation, K matches a potential reducing production to a subword of the input. If the right-hand side of this production contains a variable, K may nondeterministically switch to some production that expands that variable. This idea is formalized by Lemma 2.48. First, however, we describe K in detail .

该机器中的转换有两种:移位操作(移位操作)和ε-转换。每个作为终端或变量的a以及每个产生式B uav都会出现移位,使得:

Transitions in this automaton come in two varieties: as shifts ( shift operations ) and ε-transitions. Shifts appear for each a being a terminal or a variable and for each production B uav such that:

所有产生式B uCvC r都会发生 ε 跃迁:

ε-transitions occur for all productions B uCv and C r :

接受状态均为B u 对应已完成的生产。接受状态没有传出转换,我们将它们存储在双帧中。

Accepting states are all B u . corresponding to a completed production. Accepting states have no outgoing transitions and we record them in a double frame.

下一个引理及其推论表明K接受所有以某个有效扩展z的句柄结尾的单词z。由于K是非确定性的,我们说我们“可以”进入一种状态,这意味着机器K在非确定性处理的某个分支中进入这种状态。

The next lemma and its corollary show that K accepts all words of , which end in handles for some valid extension of . Since K is nondeterministic, we say that we “can” enter a state, by which we mean that the automaton K enters that state in some branch of nondeterministic processing.

引理2.48

Lemma 2.48

当且仅当xu并且xuvy是带有句柄uv 的有效字并且对于某些y Σ *减少产生式T uv时, K1 才能在读取输入z后进入状态。

K can enter the state after reading input z if and only if xu and xuvy is a valid word with handle uv and reducing production T uv for some y Σ *.

K证明概念的工作原理是将所选产生式的右侧与输入的一部分进行匹配。如果匹配成功,机器接受输入。如果该右侧包含变量C,则可能会发生以下两种情况之一。如果C是下一个输入符号,则简单地继续匹配所选产生式。如果C已扩展,则输入将包含从C派生的符号,因此K不确定地选择C​​的产生式,并从该产生式右侧的原点开始匹配。如果当前所选作品的右侧已完备匹配,则接受。

The proof concept K works by matching the right side of a chosen production to a portion of the input. If the match succeeds, the machine accepts the input. If that right side contains the variable C , then one of two things can happen. If C is the next input symbol, then matching the chosen production simply continues. If C has been expanded, then the input will contain symbols derived from C , so K nondeterministically chooses a production for C and starts matching from the beginning of the right side of that production. It accepts if the right side of the currently chosen production has been completely matched.

证明 首先我们进行右边的证明。假设单词z 的K进入。让我们检查K从初始状态到 的路径。我们可以将这条路径视为由 ε 转换分隔的一系列移位。移位是共享相同输出的状态之间的转换,将点在从输入读取的符号之间向右移动。在第 i步中,让产生式的形式为S iu i S i +1 v i,其中S i +1是下一步中开发的变量。倒数第二步是产生式S lul Tv l步骤,最后一步对应产生式T uv11

Proof We first carry out the proof to the right. Suppose K for a word z enters. Let us examine the path of K from its initial state to. We can think of this path as a sequence of shifts separated by ε-transitions. The shifts are transitions between states sharing the same production, moving the dot right between symbols read from the input. At the i -th step, let the production be S i u i S i +1 v i , where S i +1 is the variable expanded in the next step. The penultimate step is the step for the production S l u l T v l , and the last step corresponds to the production T u v .

输入z必须等于u 1 u 2 ... u l u = xu,因为单词u iu是从输入读取的移位符号。代入y' = v l … v 2 v 1我们看到xuvy'在G中是可导的,因为上面给出的产生式形成了一个推导,如图 2.49 所示的划分树所示。

The input z must then be equal to u 1 u 2 … u l u = xu , since the words u i and u were the shift symbols read from the input. Substituting y' = v l … v 2 v 1 we see that xuvy' is derivable in G , since the productions given above form a derivation, as shown by the parse tree illustrated in Figure 2.49.

2.49

通向xuvy'的解析树

Figure 2.49

The parsing tree leading to xuvy'

为了得到正确的单词,我们完备扩展y'中的所有变量,直到每个变量输出某个终端单词,然后我们将得到的单词称为y。单词xuvy'是正确的,因为它出现在单词w L ( G )的左侧约简中,该单词是通过完备扩展xuvy中存在的所有变量获得的终端单词。

To obtain a valid word, we fully expand all variables occurring in y' until each variable outputs a terminal word, and then call the resulting word y . The word xuvy' is valid because it occurs in the left reduction of the word w L ( G ), the terminal word obtained by fully expanding all variables occurring in xuvy .

如下图所示,uv是此约简中的句柄,其约简生成量为T uv

As seen in the figure below, uv is a handle in this reduction and its reducing production is T uv .

2.50解析树,生成带有句柄uv 的

正确单词xuvy

Figure 2.50

Parse tree leading to the correct xuvy word with handle uv

现在我们可以证明引理的相反方向。假设单词xuvy是一个有效单词,具有句柄uv和约简产生式T uv。我们将证明K对于输入xu可以进入状态1

Now we can prove the opposite direction of the lemma. Suppose the word xuvy is a valid word with handle uv and reducing production T uv . We show that K for input xu can enter the state .

xuvy的解析树如上图所示。它的根位于初始变量S 1中,并且必须包含变量T,因为T uv是xuvy归约中的第一个归约步骤。令S 2 , …, S l为从S 1T 的路径上的变量,如图所示。请注意,解析树中出现在该路径左侧的所有变量都必须未展开,否则uv将不是句柄。

The parse tree for xuvy is shown in the previous figure. It has its root at the initial variable S 1 and must contain a variable T , since T uv is the first reduction step in the reduction of xuvy . Let S 2 , …, S 1 be variables on the path from S 1 to T , as shown in the figure. Note that all variables in the parse tree that appear to the left of this path must be unexpanded, since otherwise uv would not be a handle.

在此划分树中,每个变量S i通过某种产生式S iu i S i +1 v i导致S i +1。因此,对于某些单词u iv i,语法必须包含以下产生式。

In this parse tree, every variable S i leads to S i +1 via some production S i u i S i +1 v i . Thus, the grammar must contain the following productions for some words u i and v i .

S 1 u 1 S 2 v 1

S 1 u 1 S 2 v 1

S 2 u 2 S 3 v 2

S 2 u 2 S 3 v 2

...

...

S l u l电视l

S l u l Tv l

温度 紫外线

T uv

K1 包含从初始状态到读取输入z = xu时的状态的以下路径。首先,K执行 ε 转换到 ,然后,当读取符号u 1时,它执行适当的移位,直到读取u 1后到达状态。然后,它执行 ε 转换,并在读取u 2 的同时继续移位,直到达到状态,依此类推。读取单词u 后,l进入状态,该状态通过 ε-转换导致最终,在读取u后,发现自己处于状态。1

K contains the following path from its initial state to the state when reading input z = xu . First, K makes an ε-transition to . Then, while reading symbols u 1 , it makes appropriate shifts until after reading u 1 it reaches state . It then makes an ε-transition to , and continues making shifts while reading u 2 , until it reaches state , and so on. After reading a word u , it enters state , which by an ε-transition leads to , and finally, after reading u , it ends up in state .

以下结论表明K接受所有以某个有效扩展的句柄结尾的单词。它由引理 2.48 得出,假设u = hv = ε。

The following corollary shows that K accepts all words ending with a handle for some valid extension. It follows from Lemma 2.48 by setting u = h and v = ε.

结论2.51

Motion 2.51

K可以进入接受 T h 的状态。对于输入z当且仅当z = xhh是某个有效字xhy的句柄,并减少产生式T h

K can enter the accepting state T h for input z if and only if z = xh and h is a handle for some valid word xhy with reducing production T h .

最后,我们使用第 55 页定理 1.39 证明中提出的子集构造将 NFA K转换为 DFA DK ,然后删除所有从初始状态无法到达的状态。因此,每个DK状态将包含一种或多种情况。每个接受状态至少包含一个完整的产生式。我们将引理 2.48 和推论 2.51 应用于DK,指的是包含指定情况的状态。

Finally, we transform the NFA K into a DFA DK by using the subset construction given in the proof of Theorem 1.39 on page 55 and then removing all states that are inaccessible from the initial state. Each state of DK will therefore contain one or more situations. Each accepting state contains at least one complete production. We apply Lemma 2.48 and Corollary 2.51 to DK by appealing to the states that contain the indicated situations.

现在我们可以描述DK测试了。

We can now describe the DK test .

从 CFG 语法G开始,我们构造其关联的 DFA DK。我们通过检查接受DK 的状态来确定G是否是确定性的。DK测试要求每个接受状态包含

Starting with a CFG grammar G , we construct its associated DFA DK . We determine whether G is deterministic by examining the states that accept DK . The DK test requires that each accepting state contains

  1. 恰好是一个已完成(完成)的生产,
  2. exactly one completed (finished) production,
  3. 不存在终止符号紧跟在点之后的情况,即对于a ε Σ不存在B u.av形式的情况。
  4. had no situation in which a terminal symbol immediately follows a dot, that is, no situation of the form B u.av for a Σ .

定理2.52

Theorem 2.52

当且仅当G是 DCFG 语法时,语法G通过DK测试。

A grammar G passes the DK test if and only if G is a DCFG grammar.

证明的概念 我们将证明当且仅当所有句柄都被强制执行时, DK测试才能通过。同样,我们可以说,当且仅当未强制执行某个句柄时,测试才会失败。首先,假设某个有效单词具有非强制句柄。如果我们在这个字上运行DK机器,推论 2.51 意味着DK在句柄末尾进入接受状态。 DK测试失败,因为该状态包含第二个已完成的产生式,或者具有以终止符号开头的到接受状态的传出路径。在后一种情况下,接受状态将包含点后面有结束符号的情况。

Concept of Proof We will show that the DK test passes if and only if all handles are forced. Equivalently, we can state that the test fails if and only if some handle is not forced. First, suppose that some valid word has an unforced handle. If we run the DK automaton for this word, it follows from Corollary 2.51 that DK enters the accepting state at the end of the handle. The DK test fails because this state either contains a second completed production or has an outgoing path to the accepting state, the path starting with a terminal symbol. In the latter case, the accepting state will contain the situation with a terminal symbol following the dot.

相反,如果由于接受状态包含两个已完成的产生式而导致DK测试失败,则此时我们将相关单词扩展为具有两个不同句柄的两个有效单词。类似地,如果这个状态包含一个已完成的产生式和一​​个点式产生式,并且点后面有终结点,我们可以应用引理 2.48 来获得此时具有不同句柄的两个有效扩展。构建与第二个产品相对应的正确扩展非常微妙。

Conversely, if the DK test fails because the accepting state contained two completed productions, at that point we extend the related words to two correct ones with two different handles. Similarly, if the state contains a completed production and a dotted production with a terminal following the dot, we can use Lemma 2.48 to obtain two correct extensions with different handles at that point. Constructing the correct extension corresponding to the second production is quite subtle.

证明 我们将从向右的方向开始。假设G是不确定的,我们将证明这将导致DK测试失败。我们选择正确的单词xhy,它具有非强制h句柄。因此,存在一些有效单词xhy' ,其变体句柄ĥ h,其中y'是终结词。因此,我们可以将xhy'写为xhy' = x ĥŷ

Proof We start with the rightward direction. Assume that G is nondeterministic and show that this will cause the DK test to fail . We choose a valid word xhy that has an unconstrained handle h . Thus, there is some valid word xhy' with a distinct handle ĥ h , where y' is a terminal word. We can therefore write xhy' as xhy' = x ĥŷ .

如果xh = x ĥ,则归约产生式不同,因为hĥ不是同一个句柄。因此,输入xh使DK进入包含两个已完成产生式的状态,这违反了DK测试的条件。

If xh = x ĥ , the productions of the reduction differ, since h and ĥ are not the same handle. Thus, the input xh brings DK to a state that contains two completed productions, which violates the DK test .

如果xh x ĥ,则其中之一延伸另一个。假设xh是x ĥ的真前缀。如果x ĥ是一个较短的单词,则参数与交换单词并使用y代替y'相同。令q为DK针对输入xh进入的状态。状态q必须接受,因为h是xhy 的句柄。从状态q开始,它必须引导向外转换,因为x ĥ还通过q将DK引导至接受状态。此外,这种转变被标记为终结符号,因为y' Σ +。在这种情况下,y' ε,因为x ĥ扩展了xh。因此q包含了一种情况,即在点之后有一个终止符号,这违反了DK测试。

If xh x ĥ , one of them extends the other. Suppose xh is a proper prefix of x ĥ . The argument is the same with the words swapped and using y for y' if then x ĥ is a shorter word. Let q be the state that DK enters for input xh . State q must be accepting, since h is a handle of xhy . There must be an outgoing transition from state q , since x ĥ also directs DK to an accepting state via q . Moreover, this transition is labeled a terminal symbol, since y' Σ + . In this case y' ε, since x ĥ extends xh . Hence q contains a situation with a terminal symbol immediately after the dot, which violates the DK test .

为了证明相反的情况,假设G在某个接受状态q下未能通过DK测试,并通过显示非强制句柄的存在来证明G不是确定性的。由于q是接受状态,因此它包含完整的产生式T h 。z是将DK带到状态q的词。然后z = xh,其中某个有效字xhy具有句柄h ,并且对于y Σ *具有约简产生式T h 。我们现在需要根据DK测试失败的原因来考虑两种情况。

To prove the converse, suppose that G fails the DK test in some accepting state q and we show that G is not deterministic by showing the existence of an unforced handle. Since q is an accepting state, it contains a completed production T h. Let z be a word that brings DK to state q . Then z = xh , where some valid word xhy has a handle h with a reducing production T h for y Σ *. We now need to consider two cases depending on what constitutes a failure of the DK test .

在第一种情况下,假设q有另一个已完成的产生式B ĥ。那么某个正确的单词xhy'必须有另一个句柄ĥ并具有约简产生式B ĥ。因此,h不是强制句柄。

In the first case, suppose that q has another completed production B ĥ . Then some valid word xhy' must have another handle ĥ with a reducing production B ĥ . Thus h is not a forced handle.

在第二种情况下,假设q包含产生式B u.av,其中a Σ。由于xhDK带到状态q,因此我们得到xh = x u,其中x uavŷ是有效字,并且包含uav句柄,对于某些ŷ Σ *减少产生式B uav 。为了证明h是一个非强制句柄,我们将单词v中的所有变量完备展开,得到v' Σ *;设y' = av'ŷ,我们可以看到y' Σ * 。下面的左侧归约表明xhy'是有效单词,h不是句柄。

In the second case, suppose that q contains the production B u.av , where a Σ . Since xh brings DK to state q , we get xh = x u , where x uavŷ is a valid word and contains the handle uav with the reducing production B uav for some ŷ Σ *. To show that h is an unconstrained handle, we fully expand all variables in the word v to obtain v' Σ *; let y' = av'ŷ and we can see that y' Σ *. The following left reduction shows that xhy' is a valid word and h is not a handle.

xhy' = xhav'ŷ = x uav'ŷ * x uavŷ x * S

xhy' = xhav'ŷ = x uav'ŷ * x uavŷ x * S

其中S是初始变量。我们知道x uavŷ是一个有效的单词,我们可以使用右手推导从它导出x uav'ŷ ,因此x uav'ŷ也是正确的。此外,词句柄x uav'ŷ要么位于v'内部(如果v v'),要么等于uav(如果v = v')。在每种情况下,句柄包含a或在 a之后,因此不能等于h,因为h完备在a之前。因此,h不是强制句柄。

where S is the initial variable. We know that x uavŷ is a valid word, and we can obtain x uav'ŷ from it using right-handed derivation, so x uav'ŷ is also valid. Furthermore, the word handle x uav'ŷ either lies inside v' (if v v' ) or equals uav (if v = v' ). In each case, the handle contains a or follows  a , and thus cannot equal h , since h completely precedes a . Thus, h is not a forced handle.

实际上,在构建 DFA DK 时,直接构建可能比基于 NFA K转换的过程更快。我们首先在所有引用起始变量的产生式的起点添加一个点,并将这些情况置于起始状态DK中。如果在任何这些产生式中变量C之前有一个点,我们会将点放置在所有产生式中C位于左侧的起始位置,并将这些产生式添加到状态中。只要出现新情况,我们就会继续这样做。对于点后面的任何符号c ,我们将带有标签c的出边添加到新状态,该新状态包含在点位于c之前的任何情况下通过将点移动到符号c之后获得的情况,然后添加与如前所述,点位于变量之前的产生式。

In practice, in building a DFA DK, direct construction may be faster than the procedure based on the NFA conversion K . We start by adding a dot at the starting position of all productions that refer to the initial variable and place these situations in the initial state DK . If the dot precedes the variable C in any of these productions, we place dots at the starting position in all productions where C is on the left, and add these productions to the state. We continue this procedure as long as new situations appear. For any symbol c following the dot, we add the outgoing edge labeled c to the new state containing the situations obtained by moving the dot after the symbol c in any of the situations where the dot precedes c , and then add the productions corresponding to the productions where the dot precedes the variable, as before.

2.53

Example 2.53

在这里我们将展示以下语法的DK测试失败。

Here we will show that the DK test fails for the following grammar.

S E

S E

E E + T |时间

E E + T | T

T T × a |

T T × a | a

2.54

失败的DK测试示例

Figure 2.54

Example of a failed DK test

请注意左下角的两个有问题的状态和右上角第二个,其中接受状态包括紧跟在点后面的终止符号的情况。

Notice the two problematic states at the bottom left and the second from the top right, where the accepting state contains a situation with a terminal symbol immediately following the dot.

2.55

Example 2.55

这是一个 DFA DK,表明下面所示的语法是 DCFG 语法。

Here is the DFA DK showing that the grammar shown below is a DCFG grammar.

S T

S T

T T ( T ) | ε

T T ( T ) | ε

2.56

DK测试成功示例

Figure 2.56

Example of a successful DK test

请注意,所有接受状态都满足DK测试。

Notice that all accepting states satisfy the DK test .

DPDA 和 DCFG 语法之间的依赖关系

Relationships between DPDA and DCFG grammars

在本节中,我们将展示 DPDA 和 DCFG 语法描述同一类终止语言。我们首先展示如何将 DCFG 语法转换为其 DPDA 等价语法。此转换适用于所有情况。然后我们将展示如何执行从 DPDA 到等效 DCFG 语法的反向转换。第二次转换仅适用于带有结束标记的语言。我们将等效性限制为带有结束标记的语言,因为如果没有此警告,这些模型就不等效。我们之前已经表明,包含结束标记不会影响 DPDA 识别的语言类别,但会影响 DCFG 语法生成的语言类别。如果没有结束标记,DCFG 语法仅生成 DCFL 语言的子类 - 即那些有前缀的语言(参见问题 2.52)。请注意,任何带有结束标记的语言都是前缀语言。

In this section, we show that DPDA and DCFG grammars describe the same class of end-marked languages. First, we show how to convert DCFG grammars to their equivalent DPDAs. This conversion works in all cases. Then, we show how to perform the reverse conversion from DPDAs to equivalent DCFG grammars. This latter conversion works only for languages ​​with end-marked languages. We restrict the equivalence to languages ​​with end-marked languages, since these models are not equivalent without this restriction. Earlier, we showed that including end-marked languages ​​does not affect the class of languages ​​recognized by DPDA, but it does affect the class of languages ​​generated by DCFG grammars. Without end-marked languages, DCFG grammars generate only a subclass of DCFL languages—namely, those that are prefixed (see Task 2.52). Note that every language with end-marked languages ​​is a prefixed language.

定理2.57

Theorem 2.57

当且仅当具有结束标记的语言是确定性上下文无关语言时,它是由确定性上下文无关语法生成的。

A language with end markers is generated by a deterministic context-free grammar if and only if it is a deterministic context-free language.

我们有两个方向的含义需要证明。我们首先证明每个 DCFG 语法都有一个等效的 DPDA。然后我们证明任何识别带有结束标记的语言的 DPDA 都具有等效的 DCFG 语法。我们将在两个方向上作为单独的引理进行证明。

We have two directions of implication to prove. First, we show that every DCFG grammar has an equivalent DPDA. Then, we show that every DPDA recognizing a language with end markers has an equivalent DCFG grammar. We will give the proofs in both directions as separate lemmas.

引理2.58

Lemma 2.58

每个 DCFG 语法都有相应的 DPDA 等价语法。

Each DCFG grammar has a corresponding equivalent DPDA.

证明概念我们将展示如何将 DCFG 语法G转换为等效的DPDA P。P自动机使用DFA DK如下。它模拟DK对读取的输入符号的操作,直到DK接受输入。正如我们在定理 2.52 的证明中所示,接受状态DK指示特定情况,因为G是确定性的,其中该产生式标识了扩展到目前为止输入读取的某些有效字的句柄。此外,该句柄适用于该单词的任何有效扩展,因为G 的语法是确定性的,因此适用于由P处理的完整输入单词,只要该单词属于L ( G )。因此P可以使用这个句柄来识别其输入字的第一个归约步骤,即使到目前为止它只读取了其中的一部分。

Proof Concept We show how to convert a DCFG grammar G into an equivalent DPDA P . P uses a DFA DK in the following way. It simulates the action of DK on the input symbols read until DK accepts the input. As we showed in the proof of Theorem 2.52, the accepting state DK indicates a specific situation, since G is deterministic, and this production identifies the handle of some valid extension of the input so far read. Moreover, this handle applies to any valid extension of this word, since G is deterministic, and consequently applies to the full input word processed by P , as long as this word belongs to L ( G ). Thus, P can use this handle to identify the first reduction step for its input word, even though it has only read part of it so far.

P如何识别第二个和后续的还原步骤?一种想法是对输入词执行缩减步骤,然后像以前一样将修改后的输入词输入到DK中。然而,输入数据既不能修改也不能重新加载,所以这个概念行不通。另一种方法可能是将输入复制到堆栈上并对其执行归约步骤,但随后P必须弹出整个堆栈才能将修改后的输入传递到DK机器,因此此修改后的字在以后将不可用脚步。

How can P identify the second and subsequent reduction steps? One idea is to perform a reduction step on the input word, and then feed the modified input word into the DK as before. However, the input can neither be modified nor reloaded, so this idea does not work. Another approach might be to copy the input onto a stack and perform the reduction step on it, but then P would have to pop the entire stack to feed the modified input through the DK , and thus the modified word would not be available in later steps.

我们在这里使用的技巧是将DK机器的状态存储在堆栈上,而不是将输入字放在那里。每次P读取一个输入符号并模拟DK机器的运动时,它也记录DK的状态并将其压入堆栈。当使用产生式→  u执行归约步骤时,它会删除 ||状态从堆栈中恢复,恢复DK在读取u之前所处的状态。然后它移动到这个DK状态,模拟T符号的行为,并将结果状态推送到堆栈上。然后P可以像以前一样继续读取和处理输入符号。

The trick we'll use here is to store the DK states on the stack instead of putting the input word there. Whenever P reads an input symbol and simulates a move by DK , it also records the state of DK and pushes it onto the stack. When it performs the reduction step using the production →  u , it pops | u | states off the stack, recreating the state DK was in before reading u . It then enters that state of DK , simulates its operation for symbol T , and pushes the resulting state onto the stack. P can then continue reading and processing input symbols as before.

P将初始变量压入堆栈时,它发现初始变量的输入减少了,因此它进入接受状态。

Once P pushes the initial variable onto the stack, it has found a reduction of the input to the initial variable, so it enters the accepting state.

然后我们将证明定理2.57的相反方向。

Next, we prove the opposite direction of Theorem 2.57.

引理2.59

Lemma 2.59

任何识别带有结束标记的语言的 DPDA 都有一个等效的 DCFG。

Every DPDA that recognizes a language with end tags has an equivalent DCFG.

证明的概念 该证明是对第 121 页引理 2.27 证明中所示结构的修改,描述了 PDA P到等效语法CFG G的转换。在这种情况下, PG是确定性的。在引理2.27的证明的概念中,我们将P修改为在接受之前清空堆栈,然后进入特殊的接受状态q accept。 PDA 无法独立确定它处于输入的末尾,因此P使用非确定性来猜测它处于这种情况。我们不想在构造 DPDA P时引入不确定性。相反,我们假设L ( P ) 是一种带有结束标记的语言。我们将修改P以清空其堆栈,并在读取结束标记⊣后进入原始接受状态之一时进入q接受状态。

Concept of Proof This proof is a modification of the construction given in the proof of Lemma 2.27 on page 121, describing the conversion of a PDA P into its equivalent CFG grammar G . In this case, P and G are deterministic. In the concept of the proof of Lemma 2.27, we modified P so that before accepting it empties its stack and then enters a special accepting state q accept . PDA cannot independently determine that it is at the end of its input, so P exploited nondeterminism to guess that it is in this situation. We do not want to introduce nondeterminism in the construction of DPDA P . Instead, we use the assumption that L ( P ) is a language with end markers. We modify P so that it empties its stack and enters the state q accept wheneverit enters one of the original accepting states after reading the end marker ⊣ .

然后我们以几乎与之前相同的方式构建语法G。简单地将原始构造应用于 DPDA 会产生几乎确定性的语法,因为 CFG 语法的推导与 DPDA 计算密切相关。事实证明,这种语法只有一种小的、可修复的方式是不确定的。

We then construct the grammar G in much the same way as before. A straightforward application of the original construction to DPDA yields a nearly deterministic grammar, since the derivations of the CFG grammars closely relate to the computations of DPDA. This grammar turns out to be non-deterministic only in one small, fixable way.

原始结构引入了A pq A pr A rq形式的产生式,这可能会导致歧义。这些产生式包括这样的情况:A pq生成一个字,将P从状态p带到状态q,两端都有空堆栈,在此过程中堆栈为空。这个替换对应于此时计算的划分。但是,如果堆栈被多次清空,则可能会出现多次分裂。每个分区对应不同的分区树,因此生成的语法是不明确的。我们可以通过修改语法来解决这个问题,只在堆栈清空的最后一个点分割计算,从而消除这种歧义。为了说明这一点,类似但更简单的情况发生在歧义语法中

The original construction introduces productions of the form A pq A pr A rq , which can cause ambiguity. These productions include the case where A pq generates a word that takes P from state p to state q with an empty stack at both ends, and the stack is emptied in the process. This substitution corresponds to a split computation at that point. However, if the stack is emptied multiple times, multiple splits are possible. Each of these splits corresponds to a different parse tree, so the resulting grammar is ambiguous. We can fix this problem by modifying the grammar so that it splits the computation only at the last point at which the stack is emptied, thereby removing this ambiguity. To illustrate, a similar but simpler situation occurs in the ambiguous grammar

S T

S T

T T T | ( T ) | ε

T T T | ( T ) | ε

这相当于明确且确定性的语法

which is equivalent to an unambiguous and deterministic grammar

S T

S T

T T ( T ) | ε

T T ( T ) | ε

然后我们将使用DK测试证明修改后的语法是确定性的。该语法旨在模拟 DPDA。正如我们在引理 2.27 中所示,A pq生成将P从空堆栈状态p带到空堆栈状态q的确切单词。我们将使用P的确定性来证明G的确定性,结果证明,为有效字(因此,特别是涉及变量符号)定义P的计算以便分析其在句柄上的操作是有用的。然后,我们将使用P 的确定性行为来表明句柄是强制执行的。

We then use the DK test to show that the modified grammar is deterministic. This grammar is designed to simulate DPDA. As we showed in Lemma 2.27, A pq generates exactly those words that take P from a state p with an empty stack to a state q with an empty stack. We prove the determinism of G using the determinism of P , and it turns out that it is useful to define the computation of P for valid words (and thus, in particular, for variable symbols) so as to analyze its behavior on handles. We then use the deterministic behavior of P to show that handles are enforced.

证明 P = ( Q , Σ , Γ , δ, q 0 , { q Accept }) 为 DPDA,我们从中构造语法G。初始变量为Aq 0 ,q Accept。第121页的结构包括第1、2和3部分,为方便起见,此处重复。

Proof Let P = ( Q , Σ , Γ , δ, q 0 , { q accept }) be a DPDA from which we construct the grammar G . The initial variable is Aq 0 ,q accept . The construction on page 121 contains parts 1, 2, and 3, which are repeated here for convenience.

  1. 对于所有p , q , r , s ε Q , u ε Γa , b ε Σ ε,如果 δ( p , a , ε) 包含 ( r , u ) 且 δ( s , b , u ) 包含 ( q , ε),我们将产生式A pqaA rs b添加到G中。
  2. For each p , q , r , s Q , u Γ and a , b Σ ε , if δ( p , a , ε) contains ( r , u ) and δ( s , b , u ) contains ( q , ε ), we add to G the production A pq aA rs b .
  3. 对于每个p , q , r Q我们将产生式A pqA pr A rq插入到G中。
  4. For every p , q , r Q we insert into G the production A pq A pr A rq .
  5. 最后,对于每个p Q,我们将产生式A pp → ε 添加到G中。
  6. Finally, for each p Q we add to G the production A pp ε.

我们将修改此结构以避免引入歧义。为此,我们将类型 1 和 2 的产生式组合成类型 1-2 的产生式,提供相同的效果。

We will modify this construction to avoid introducing ambiguity. To do this, we combine the productions of types 1 and 2 into a single production of type 1-2, which provides the same effect.

1-2 .对于每个p , q , r , s , t Q , u Γa , b Σ ε , 如果 δ( r , a , ε) = ( s , u ) 且 δ( t , b , u ) = ( q , ε ),我们将产生式A pqA pr aA st b添加到G中。

1-2 . For every p , q , r , s , t Q , u Γ and a , b Σ ε , if δ( r , a , ε) = ( s , u ) and δ( t , b , u ) = ( q , ε ), we add to G the production A pq A pr aA st b .

为了证明修改后的语法生成相同的语言,请考虑原始语法中的任何派生。对于与类型 2 产生式一致的任何替换A pq A pr A rq,我们可以将r作为P 的最右边的状态,因为堆栈一路清空,修改第 123 页上的语句 2.31 的证明以在此精确地选择r方式。然后,后续替换A rq必须使用产生式A rq aA st b对其进行扩展,其类型为 1。我们可以将这两个替换组合成单个产生式A pq A pr aA st b,其类型为 1- 2.

To show that the modified grammar generates the same language, consider any derivation in the original grammar. For any substitution A pq A pr A rq that is compatible with a type-2 production, we can take r to be the rightmost state of P when the stack empties along the way, modifying the proof of Proposition 2.31 on page 123 to choose r in just this way. Then a later substitution A rq must expand it using the production A rq aA st b , which is of type 1. We can combine these two substitutions into a single production A pq A pr aA st b , which is of type 1-2.

相反,在使用修改语法的推导中,如果我们将每个产生式A pq A pr aA st b替换为类型 2产生式A pq A pr A rq,后跟类型 1 产生式A rq aA st b,我们得到同样的结果。

Conversely, in the derivation using the modified grammar, if we replace each production A pq A pr aA st b with a type-2 production A pq A pr A rq followed by a type-1 production A rq aA st b , we get the same result.

我们现在将使用DK测试来证明G是确定性的。为此,我们将探讨P如何对有效单词进行操作,扩展其输入字母表和转换函数以处理变量符号,而不仅仅是终结符。我们将所有符号A pq添加到输入字母表P中,并通过定义 δ( p , A pq , ε) = ( q , ε) 来扩展其传递函数 δ。我们将涉及A pq的所有其他转换设置为Ø。为了保持P 的确定性行为,我们在P读取A pq时排除 ε 移动。

We now use the DK test to show that G is deterministic. To do this, we examine how P behaves on valid words by extending its input alphabet and transition function to process variable symbols instead of just terminals. We add all the symbols A pq to P's input alphabet and extend its transition function δ by defining δ( p , A pq , ε) = ( q , ε ). We set all other transitions involving A pq to Ø . To preserve the deterministic behavior of P , we exclude ε-moves when P reads A pq .

以下陈述适用于属于L ( G ) 的每个单词w的推导,使得

The following statement applies to the derivation of any word in L ( G ) such that

A q 0 ,q接受= v 0 v 1 v i ·… v k = w

A q 0 ,q accept = v 0 v 1 v i ·… v k = w .

声明2.60

Statement 2.60

如果P加载包含变量A pqvi ,则它在加载A pq之前立即进入状态p

If P loads v i containing variable A pq , then it enters state p immediately before A pq is loaded .

该证明使用i上的归纳法,即从 A q 0 ,q Accept导出vi所需的步骤数。

The proof uses induction on i , the number of steps needed to derive v i from A q 0 ,q accept .

基本步骤 i = 0。

Basic step : i = 0.

在这种情况下,v i = A q 0 ,q Accept,并且P从状态q 0开始,所以这一步完成。

In this case v i = A q 0 , q accept , and P starts in state q 0 , so this step is satisfied.

归纳步骤:我们假设某个i的假设为真,并证明i + 1 的假设为真。

Inductive step : We assume that the hypothesis is true for some i and prove it is true for i + 1.

首先,我们考虑v i = xA pq y i A pq是步骤v i v i +1中代入的变量的情况。归纳假设意味着P在读取x之后、读取符号A pq之前立即进入状态p。根据G语法的结构,替换产生式可以有两种类型:

First, we consider the case when v i = xA pq y and A pq is the variable being substituted in the step v i v i +1 . The inductive hypothesis implies that P enters state p after reading x , immediately before reading the symbol A pq . According to the construction of the grammar G, substitution productions can be of two types:

  1. A pq A pr aA st b
  2. A pq A pr aA st b or
  3. A pp ε。
  4. And pp ε.

因此,要么v i +1 = xA pr aA st by,要么v i +1 = xy,具体取决于使用的产生式类型。在第一种情况下,当P读取v i +1中的A pr aA st b时,我们知道它从状态p开始,因为它刚刚完成读取x。当Pv i +1处读取A pr aA st b时,它根据所使用的产生式经历一系列状态rstq 。因此,它在加载A pr之前立即进入状态p ,在加载A st之前立即进入状态s,因此对于这两次出现的变量,该语句成立。对于y部分中变量的出现,该语句也成立,因为当P读取b时,它进入状态q然后读取单词y。在输入v i的情况下,在读取y之前也会立即进入状态q,因此计算与单词v iv i +1的y部分匹配。当然,x部分的计算是一致的。因此,该陈述对于v+1成立。在第二种情况下,没有引入新变量,因此我们只需要注意计算与单词v iv i +1的xy部分相匹配。这样就完成了该命题的证明。

Thus, either v i +1 = xA pr aA st by , or v i +1 = xy , depending on the type of production used. In the first case, when P reads A pr aA st b into v i +1 , we know that it starts in state p , since it has just finished reading x . When P reads A pr aA st b into v i +1 , it goes through the sequence of states r , s , t , and q , according to the production used. Thus, it enters state p immediately before reading A pr , and state s immediately before reading A st , so the statement holds for these two occurrences of the variables. The statement also holds for the occurrences of the variables in part y , since when P reads b , it enters state q and then reads word y . For input v i , it also enters state q immediately before reading y , so the computation holds for the y portions of words v i and v i +1 . Obviously, the computations are consistent for the x part . Thus, the statement is satisfied for v i +1 . In the second case, no new variables are introduced, so we only need to note that the computations are consistent for the x and y parts of the words v i and v i +1 . This completes the proof of the statement.

声明2.61

Statement 2.61

G通过了DK测试。

G passes the DK test .

我们将证明每个接受DK 的州都满足DK测试的条件。我们选择这些接受状态之一。它包含R的完整生成。该生产可以是以下两种形式之一:

We will show that each of the states accepting DK satisfies the test DK . We choose one of these accepting states. It contains the completed production R . This production can be of one of two forms:

  1. A pq A pr aA st b
  2. A pq A pr aA st b .
  3. 一个应用 .
  4. A pp .

在这两种情况下,我们需要表明接受状态不能包含:

In both situations we need to show that the accepting state cannot contain:

a) 其他已完成的生产或

a) other finished production or

b) 点后面紧接着包含终结符号的情况。

b) a situation that contains a terminal symbol immediately after the dot.

让我们分别考虑这四种情况。在每种情况下,我们都会首先考虑单词z,它将DK带到上面选择的接受状态。

Let's consider each of these four cases separately. In each case, we'll start by considering a word from that takes DK to the accepting state chosen above.

案例1a。在本例中,它是已完成的类型 1-2 生产。对于此接受状态中的每个产生式,z必须以该产生式中的点之前的符号结尾,因为DK对于z进入此状态。因此,点前面的符号在所有此类产生式中必须一致。这些符号是R中的A pr aA st b,因此任何其他已完成的类型 1-2 的产生式都必须在右侧具有完备相同的符号。由此可见,左边的变量也必须匹配,因此产生式必须相同。

Case 1a . In this case is a completed production of type 1-2. For each production in this accepting state, z must end with the symbols preceding the dot in this production, since DK enters this state for z . Thus, the symbols preceding the dot must match in all such productions. These symbols are A pr aA st b w R , so every other completed production of type 1-2 must have exactly the same symbols on the right-hand side. It follows that the variables on the left-hand side must also match, so the productions must be the same.

假设接受状态包含R和一些已完成的类型 3 的ε-产生式T。从R我们知道z以A pr aA st b结尾。此外,我们知道P在z 的最末尾执行堆栈弹出操作,因为由于语法G的结构该操作发生在R的产生过程中的此时。根据我们构建DK的方式,某个状态下完整的 ε-产生式必须源自同一状态下的情况,其中该点不在最开始或紧接在任何变量之前。 (我们在初始状态DK中有一个例外,其中一个点可能出现在产生式的开始处,但是我们的接受状态不能是初始状态,因为它包含类型 1-2 的完整产生式。)在G语法中,这个表示T源自类型 1-2 的情况,其中第二个变量前面有一个点。从G的构造中,我们知道推动移动发生在点之前。由此可见,P在z 的最后执行推移动,这与前一句相矛盾。因此,不可能存在完整的T ε-生产。结合这些考虑,我们发现在我们的接受状态下不存在其他已完成的生产。

Suppose the accepting state contains R and some completed ε-production T of type 3. From R we know that z ends in A pr aA st b . Furthermore, we know that P performs the popping operation at the very end of z , since this operation occurs at that point in the production R , by the construction of the grammar G . According to the way we have constructed DK , a completed ε-production in a state must be derived from a situation in the same state where the dot is not at the very beginning and does not immediately precede any variable. (There is an exception in the initial state DK , where the dot may appear at the beginning of a production, but our accepting state cannot be the initial state, since it contains a completed production of type 1-2.) In grammar G , this means that T is derived from a situation of type 1-2, where the dot precedes the other variable. From the construction of G we know that the push move occurs immediately before the dot. It follows that P makes a push move at the very end of z , which contradicts the previous sentence. Thus, there can be no completed ε-production T . Combining these considerations, we see that no other completed production can occur in our accepting state.

案例2a。这次R是完成的 ε-产生式A pp  →  。我们将证明没有其他已完成的ε -产生式A qq  →  不能与R共存。如果存在,则前面的语句表明P在读取z后必须处于状态p ,并且在读取z后也必须处于q状态。由此可知p = q,因此两个完成的ε -产生式是相同的产生式。

Case 2a . This time R is a completed ε-production of A pp  →  . . We will show that no other completed ε -production of A qq  →  . can coexist with R . If it did, the previous statement shows that P must be in state p after reading z and must be in state q after reading z . It follows that p = q , and therefore both completed ε -productions are the same production.

案例1b。在这种情况下,R是类型 1-2 的成品。从情况 1a 中,我们知道P在单词z的末尾执行出栈操作。假设接受状态还包含一种情况T,其中终端符号紧跟在点之后。然而,从T 的产生式中我们知道P不会在单词z的末尾从堆栈中获取快照。这个矛盾说明这样的情况是不可能发生的。

Case 1b . In this case R is a completed production of type 1-2. From case 1a we know that P pops at the end of word z . Suppose that the accepting state also contains a situation T in which the terminal symbol immediately follows a dot. However, from production T we know that P does not pop at the end of word z . This contradiction shows that such a situation cannot occur.

案例2b。这里R是完整的 ε-产生式。假设接受状态还包含一种情况T,其中终端符号紧跟在点之后。但是,由于T的类型为 1-2,因此变量符号必须紧接在点之前,因此z以该符号结尾。此外,当P读取z时,它准备读取非 ε 符号,因为点后面是终结符。与情况 1a 一样,完整的 ε 产生式R源自类型 1-2 S情况,其中点紧邻第二个变量。 (和之前一样,我们知道这个接受状态不可能是DK 的初始状态,因为该点没有出现在T 的开头。)因此S中的点前面紧接着某个符号â Σ,因此z结束在一个。在这种情况下,要么符号â Σ,要么â = ε ,但由于z以变量符号结尾,则 â Σ,因此â  = ε 。由此可见,在P读取z之后,但在将 ε 输入移动到进程â之前,它准备读取 ε。上面我们还表明P此时已准备好读取非 ε 符号。然而,DPDA 不能同时执行输入的 ε 移动和从输入中读取非 ε 符号的移动,因此这种情况是不可能的,也不会发生。

Case 2b . Here R is a completed ε-production. Suppose that the accepting state also contains a situation T in which a terminal symbol immediately follows a dot. However, since T is of type 1-2, the dot must be immediately preceded by a variable symbol, and thus z ends with that symbol. Moreover, when P reads z , it is prepared to read a non-ε symbol, since the dot is followed by a terminal. As in case 1a, the completed ε-production R is derived from a situation S of type 1-2 in which the dot immediately precedes the second variable. (As before, we know that this accepting state cannot be the initial state of DK , since the dot does not occur at the beginning of T .) Thus the dot in S is immediately preceded by some symbol â Σ , and thus z ends with â. In this situation, either the symbol â Σ , or â = ε, but since z ends in a variable symbol, then â Σ , so â  = ε. It follows that after P reads z , but before it makes an ε-move of the input to process â , it is prepared to read ε. We also showed above that P is prepared to read a non-ε symbol at this point. However, DPDA cannot make both an ε-move of the input and a move to read a non-ε symbol from the input, so this situation is impossible and does not occur.

LR(k) 解析和语法

LR(k) parsing and grammars

确定性上下文无关语言具有非常重要的实际意义。他们的语言成员测试和解析算法基于 DPDA,因此非常高效,同时还涵盖了大多数编程语言所属的丰富的上下文无关语言类别。然而,使用 DCFG 语法来表达某些 DCFL 语言并不方便,强制执行所有句柄的要求常常使得编写直观的 DCFG 语法变得困难。

Deterministic context-free languages ​​are of great practical importance. Their language membership testing and parsing algorithms are based on DPDA and are therefore efficient, while at the same time covering the rich class of context-free languages ​​that most programming languages ​​belong to. However, expressing some DCFL languages ​​in terms of DCFG grammars is inconvenient. The requirement that all handles be enforced often makes it difficult to write intuitive DCFG grammars.

幸运的是,一类更广泛的语法称为 LR( k ) 语法,它提供了两全其美的方法。它们与 DCFG 语法足够接近,可以直接转换为 DPDA,而且对于许多应用程序来说也具有足够的表达能力。

Fortunately, a broader class of grammars called LR( k ) grammars provide the best of both worlds. They are close enough to DCFG grammars to allow direct conversion to DPDA, while also being expressive enough for many applications.

LR( k ) 文法的算法引入了先行符号概念。在 DCFG 语法中,所有句柄都是强制的。句柄仅取决于有效字中直到句柄(包括句柄)的符号,而不取决于句柄后面的终结符。在 LR( k ) 语法中,句柄还可以依赖于句柄后面的符号,但仅依赖于其中的前k个。首字母缩略词 LR( k ) 代表:从左到右处理最右推导或等效的左缩减)和k 个预览符号。

The algorithms for LR( k ) grammars introduce the notion of lookahead symbols . In DCFG grammars, all handles are coerced. A handle depends only on the symbols in the valid word up to and including the handle, but not on the terminal symbols that follow the handle. In an LR( k ) grammar, a handle may also depend on the symbols that follow the handle, but only on the first k of them. The acronym LR( k ) stands for: Left to right processing , Rightmost derivations ( or equivalently, leftmost reductions), and k lookahead symbols.

为了精确地表达这一点,令h为正确单词v = xhy的句柄。如果h是每个有效单词xhŷ的唯一句柄,则我们说h通过 k 个符号的预览强制执行的,其中ŷ Σ * 并且yŷ在前k个符号上相同。 (如果这些单词中的任何一个短于k,则这些单词必须匹配较短单词的长度。)

To formulate this precisely, let h be a handle to a valid word v = xhy . We say that h is enforced by a k-symbol lookup if h is a unique handle for each valid word xhŷ , where ŷ Σ * and where y and ŷ are identical over the first k symbols. (If any of these words is shorter than k , the words must match up to the length of the shorter one.)

定义2.62

Definition 2.62

LR( k ) 语法是上下文无关语法,因此通过查看k 个符号来强制执行每个有效单词的句柄。

The grammar LR( k ) is a context-free grammar such that the handle of each valid word is forced by a lookup of k symbols.

这意味着DCFG语法是LR(0)语法。我们可以证明对于每个k都可以将 LR( k ) 转换为 DPDA。我们已经证明 DPDA 等价于 LR(0) 文法。由此可见,LR( k ) 文法对于所有k来说在表达强度上是等效的,并且它们都描述了 DCFL 语言。以下示例表明,对于指定某些语言,LR(1) 语法比 DCFG 语法更方便。

This means that the grammar DCFG is an LR(0) grammar. We can show that for every k one can convert LR( k ) to DPDA. We have already shown that DPDAs are equivalent to LR(0) grammars. It follows that the LR( k ) grammars are equivalent in expressiveness for all k and that they all describe DCFL languages. The following example shows that LR(1) grammars are more convenient than DCFG grammars for specifying certain languages.

为了避免繁琐的符号和技术细节,我们将展示如何仅在k = 1 的特殊情况下将 LR( k ) 语法转换为 DPDA 。一般情况的转换基本上以相同的方式完成。

To avoid tedious notation and technical details, we will show how to transform LR( k ) grammars to DPDA only for the special case where k = 1. The conversion in the general case is done in essentially the same way.

首先,我们提出针对 LR(1) 语法修改的DK测试的变体。我们将其称为DK测试预览 1 或简称为DK测试1。和之前一样,我们将构造 NFA,这次称为K 1,然后将其转换为 DFA DK 1。每个状态K 1都包含情况T u v,还有一个终结符号a,称为监视符号,我们将其写为1。此状态表明K 1刚刚读取了单词u,它是句柄uv的一部分,前提是v跟随ua跟随v

We first present a variant of the DK test modified for LR(1) grammars. We will call it the DK test with look-ahead 1 or simply the DK 1 test . As before, we construct an NFA, this time called K 1 , and convert it to a DFA DK 1 . Each of the states K 1 contains the situation T u . v , and in addition a terminal symbol a , called the look-ahead symbol , which we write as . Such a state shows that K 1 has just read a word u , which is part of handle uv , provided that v follows u and that a follows v .

正式的结构与前面所示的类似。初始状态包含到每个产生式的状态的ε1移动,参考初始变量S 1和每个a ε Σ。移位会导致1输入x的状态发生转换,其中x是变量符号或终结符。 ε-转换导致1 每个产生式C r移出状态,其中b是可以从v导出的任何终端词的第一个符号。如果v导出 ε,我们添加b = a。接受状态是1 已完成的产生式B u 的所有状态a Σ

The formal construction proceeds similarly to that previously shown. The initial state contains an ε -move to a state for each production referring to the initial variable S 1 and each a Σ . Shifts cause a transition from a state for input x , where x is a variable symbol or a terminal symbol. ε-transitions cause a move from a state for each production C r , where b is the first symbol of any terminal word that can be derived from v . If v derives ε , we add b = a . The accepting states are all states for the completed productions B u . and a Σ .

R 1为具有预览符号a 1 的成品,令R 2为具有预览符号a 2 的情况。我们会说R 1R 2一致如果

Let R 1 be a completed production with lookahead symbol a 1 and let R 2 be a situation with lookahead symbol a 2 . We will say that R 1 and R 2 are consistent if

  1. R 2完成且a 1 = a 2
  2. R 2 is complete and a 1 = a 2 or
  3. R 2未完成,点后面紧跟着一个1 。
  4. R 2 is not completed and a 1 follows immediately after the period.

我们现在可以描述DK 1测试。我们构建DFA DK 1。该测试要求没有接受状态包含两种兼容的情况。

We can now describe the test DK 1 . We construct the DFA DK 1 . The test requires that no accepting state contains two compatible situations.

定理2.63

Theorem 2.63

当且仅当G是 LR(1) 语法时, G通过DK 1测试。

G passes the DK 1 test if and only if G is an LR(1) grammar.

证明推论 2.51 的概念 仍然适用于DK 1,因为我们可以忽略偷看的符号。

The Concept of Proof Corollary 2.51 still applies to DK 1 , since we can ignore the lookahead symbols.

2.64

Example 2.64

此示例表明以下语法通过了DK 1测试。回想一下,在例 2.53 中,我们表明该语法未通过 DK 测试。因此,我们有一个 LR(1) 语法的示例,但不是 DCFG 语法。

This example shows that the grammar below passes the DK 1 test . Recall that in Example 2.53 we showed that this grammar fails the DK test. We thus have an example of a grammar that is LR(1) but is not a DCFG grammar.

S E

S E

E E + T |时间

E E + T | T

T T × a |

T T × a | a

2.65

通过DK 1测试

Figure 2.65

Passing the DK 1 test

定理2.66

Theorem 2.66

当且仅当具有结束标记的语言是 DCFL 语言时,它是由 LR(1) 语法生成的。

A language with end markers is generated by an LR(1) grammar if and only if it is a language of class DCFL.

我们已经证明,每种 DCFL 语言都有 LR(0) 语法,因为 LR(0) 语法与 DCFG 语法相同。这就证明了蕴涵的方向是向左的。仍然需要证明以下引理,该引理展示了如何将 LR(1) 语法转换为 DPDA。

We have already shown that every DCFL language has an LR(0) grammar, since an LR(0) grammar is the same as a DCFG grammar. This proves the left direction of implication. It remains to prove the following lemma, which shows how to convert an LR(1) grammar into a DPDA.

引理2.67

Lemma 2.67

对于每个 LR(1) 文法,都有一个 DPDA 等价文法。

For every LR(1) grammar there is an equivalent DPDA.

证明的概念 我们构造P 1 ,它是引理 2.58 中提出的DPDA P的修改版本。 P 1读取其输入并模拟DK 1的行为,使用堆栈来跟踪如果到目前为止已应用所有归约步骤, DK 1将处于的状态。此外, P 1向前读取一个符号并将该预览信息存储在其有限状态存储器中。每当DK 1到达接受状态时, P 1检查正在监视的符号以确定是否执行归约步骤以及如果该状态存在多种可能性则执行什么步骤。因为语法是 LR(1),所以只能应用一个选项。

Proof Concept We construct P 1 , a modified version of the DPDA P presented in Lemma 2.58. P 1 reads its input and simulates the operation of DK 1 , using a stack to keep track of the state DK 1 would be inif all reduction steps had been applied so far. In addition, P 1 reads one symbol forward and stores this lookahead information in its finite state memory. Whenever DK 1 reaches an accepting state, P 1 examines the lookahead symbol to determine whether to perform a reduction step and which step to perform if there are multiple possibilities in that state. Only one option can be applicable, since the grammar is LR(1).

练习

Exercises

2.1回想一下我们在例 2.4 中展示的 CFG G 4语法。为了方便起见,我们将其变量重命名为单个字母,如下所示。

2.1 Recall the grammar CFG G 4 that we showed in Example 2.4. For convenience, we change the names of its variables to single letters, as we show below.

E E + T |时间

E E + T | T

T T × F | F

T T × F | F

F ( E ) |

F ( E ) | a

提供下面每个单词的解析树和推导。

Provide parse trees and derivations for each of the following words.

一个.a

a. a

b. a + a

一个 +一个+一个

c. a +a+ a

d. ((a))

d. ((a))

2.2 a. 使用语言A = { a m b n c n : m , n ≥ 0} 和B = { a n b n cm : m , n 0} 与例 2.36 一起显示该类上下文无关语言的集合不会因交集而封闭。

2.2 a. Use the languages ​​A = { a m b n c n : m , n ≥ 0} and B = { a n b n c m : m , n ≥ 0} together with Example 2.36 to show that the class of context-free languages ​​is not closed under intersection.

b. 使用(a)部分和德摩根定律(定理0.20)表明上下文无关语言的类对于补集不是封闭的。

b. Use part (a) and DeMorgan's law (Theorem 0.20) to show that the class of context-free languages ​​is not closed under complement.

A 2.3 回答下列关于下列上下文无关语法G 的问题。

A 2.3 Answer the following questions about the following context-free grammar G .

R XRX | S

R XRX | S

S a T b | b

S a T b | b T a

T XTX | X | ε

T XTX | X | ε

X 一个|

X a | b

a. G语法 的变量是什么?

a. What are the variables of grammar G ?

b. G语法 的终结符是什么?

b. What are the terminals of grammar G ?

c.哪个变量是G语法 的初始变量?

c. Which variable is the initial variable of grammar G ?

d. 说出属于L ( G ) 的三个单词。

d. Give three words that belong to L ( G ).

e. 给出三个不属于L ( G ) 的单词。

e. Give three words that do not belong to L ( G ).

f. 正确或错误:T aba

f. True or false: T aba .

g. 正确或错误:T * aba

g. True or false: T * aba .

h. 正确或错误:T T

h. True or false: T T .

i. 正确或错误:T * T

i. True or false: T * T .

j. 对或错:XXX * aba

j. True or false: XXX * aba .

k. 正确或错误:X * aba。

k. True or false: X * aba.

l. 正确或错误:T * XX

l. True or false: T * XX .

m. 正确或错误:T * XXX

m. True or false: T * XXX .

名词 正确或错误: S * ε。

n . True or false: S * ε.

o.用您自己的话,用自然语言 描述语言L ( G )。

o. Describe the language L ( G ) in your own words, in natural language.

2.4 提供生成以下语言的上下文无关语法。在所有点上, Σ 的字母表都是 { 0 , 1 }。

2.4 Give context-free grammars that generate the following languages. At all points, the alphabet of Σ is { 0 , 1 }.

A a. { w : w至少包含三个 1}

A a. { w : w contains at least three ones}

b. { w : w以相同的符号开始和结束 }

b. { w : w starts and ends with the same symbol }

c. { w:长度w是奇数}

c. { w : length of w is odd number}

A d. { w : w的长度为奇数,中间符号为0 }

And d. { w : length of w is odd number and its middle symbol is 0 }

e. { w : w = w R,即w是回文}

e. { w : w = w R , so w is a palindrome}

f. 空集

f. Empty set

2.5 提供练习2.4中各语言的堆栈机的非正式描述和状态图。

2.5 Give informal descriptions and state diagrams of pushdown machines for the languages ​​from Exercise 2.4.

2.6 提供生成以下语言的上下文无关语法。

2.6 Give context-free grammars that generate the following languages.

A a.字母表 { a , b } 上方包含的a多于b 的 单词集合

A a. The set of words over the alphabet { a , b } containing more a than b

b. 语言补语 { a n b n : n ≥ 0}

b. The complement of the language { a n b n : n ≥ 0}

并且c. { w # x : w R是w的子词x , x { 0 , 1 } * }

And c. { w # x : w R is a subword of x for w , x { 0 , 1 } * }

d . { x 1 # x 2 ## x k : k1 ,对于某些ij x i = x j R }​

d. { x 1 # x 2 ## x k : k ≥ 1, each x i { a , b } * and for some i and j x i = x j R }

A 2.7 给出练习 2.6 中语言的 PDA 的非正式描述。

A 2.7 Give an informal description of PDA for the languages ​​in Exercise 2.6.

A 2.8 证明在第 103 页的语法G 2中,单词the girls Touching the boy with the Flower有两个不同的左手推导。 (用日常语言)描述这句话的两种不同含义。

A 2.8 Show that in grammar G 2 on page 103 the word the girl touches the boy with the flower has two different left-hand derivations. Describe (in everyday language) the two different meanings of this sentence.

2.9 引入生成语言的上下文无关语法

2.9 Introduce a context-free grammar that generates a language

A = { a i b j ck : i = jj = k,其中i , j , k ≥ 0}。

A = { a i b j c k : i = j or j = k , where i , j , k ≥ 0}.

这个语法有歧义吗?为什么是或为什么不是?

Is this grammar ambiguous? Why or why not?

2.10给出练习 2.9 中识别语言A 的 堆栈自动机的非正式描述。

2.10 Give an informal description of the pushdown automaton that recognizes language A from Exercise 2.9.

2.11使用定理 2.20 中所示的过程将练习 2.1 中给出的 CFG G 4语法转换为其 PDA 等效语法。

2.11 Convert the CFG G 4 given in Exercise 2.1 into its equivalent PDA using the procedure shown in Theorem 2.20.

2.12使用定理 2.20 中所示的过程将练习 2.3 中给出的 CFG G语法转换为其等效的 PDA 语法。

2.12 Convert the CFG G given in Exercise 2.3 into its equivalent PDA using the procedure shown in Theorem 2.20.

2.13G = ( V , Σ , R , S ) 为以下语法。V = { S , T , U }; Σ = { 0 , # }; R是生产集:

2.13 Let G = ( V , Σ , R , S ) be the following grammar. V = { S , T , U }; Σ = { 0 , # }; R is the set of productions:

S T T |

S T T | U

T 0 T | 0 | 0 #

T 0 T | T 0 | #

U 0 U 00 | #

U 0 U 00 | #

a.用日常语言 描述L ( G )。

a. Describe L ( G ) in everyday language.

b. 证明L ( G )不是正则语言。

b. Prove that L ( G ) is not a regular language.

2.14 使用定理 2.9 中所示的过程将以下 CFG 语法转换为等效的乔姆斯基范式语法。

2.14 Convert the following CFG grammar into an equivalent Chomsky normal form grammar using the procedure shown in Theorem 2.9.

A BAB || ε

A BAB | B | ε

B 00 | ”

B 00 | "

2.15 给出一个反例,表明以下构造并不能证明上下文无关语言的类在 Kleene 闭包下是封闭的。令A为由 CFG 语法G = ( V , Σ , R , S )生成的 CFL 。我们添加一个新规则S SS并将生成的语法称为G'。该语法旨在生成A *

2.15 Give a counterexample to show that the following construction does not prove that the class of context-free languages ​​is closed under Kleene closure. Let A be a CFL generated by the CFG grammar G = ( V , Σ , R , S ). We add a new rule S SS and call the resulting grammar G' . This grammar is supposed to generate A * .

2.16 证明上下文无关语言的类相对于并集、串联和克林闭包的标准操作是闭集的。

2.16 Prove that the class of context-free languages ​​is closed under the standard operations of union, concatenation, and Kleene closure.

2.17 通过展示如何将正则表达式直接转换为等效的上下文无关语法,使用练习 2.16 的结果提供另一种证明,证明每种正则语言都是上下文无关语言。

2.17 Use the result of Exercise 2.16 to give another proof of the fact that every regular language is context-free by showing how to directly transform a regular expression into its equivalent context-free grammar.

任务

Tasks

A 2.18 a.C为上下文无关语言, R为正则语言。证明C R是上下文无关语言。

A 2.18 a. Let C be a context-free language and R a regular language. Prove that C R is a context-free language.

b.A = { w : w { a , b , c } *w包含相同的数abc }。使用 (a) 证明A不是 CFL。

b. Let A = { w : w { a , b , c } * and w contains equal numbers a , b , and c }. Use part (a) to show that A is not a CFL language.

*2.19 令CFG G为以下语法。

*2.19 Let CFG G be the following grammar.

S a S b |Y |

S a S b | b Y | Y a

Y b Y |Y | ε

Y b Y | a Y | ε

用日常语言对L ( G )进行简单描述。使用此描述来表示L(G)的 CFG 语法,L(G) 是语言L ( G ) 的补集。

Give a simple description of L ( G ) in ordinary language. Use this description to provide a CFG for L(G) , the complement of L ( G ).

2.20A / B = { w : wx A对于某些x B }。证明如果A是上下文无关语言,B是正则语言,则A / B是上下文无关语言。

2.20 Let A / B = { w : wx A for some x B }. Prove that if A is a context-free language and B is a regular language, then A / B is a context-free language.

*2.21Σ = { a , b }。给出一个 CFG 语法,该语法生成​​一种包含两倍于b 的a 的单词的语言。证明这个语法是正确的。

*2.21 Let Σ = { a , b }. Give a CFG grammar that generates a language of words containing twice as many a as b . Prove that the grammar is correct.

*2.22C = { x # y : x , y { 0 , 1 } *x y }。证明C是上下文无关语言。

*2.22 Let C = { x # y : x , y { 0 , 1 } * and x y }. Show that C is a context-free language.

*2.23D = { xy : x , y { 0 , 1 } * i | x | = | y |,但x y }。证明D是上下文无关语言。

*2.23 Let D = { xy : x , y { 0 , 1 } * and | x | = | y |, but x y }. Prove that D is a context-free language.

*2.24E = { a i b j | i j且 2 i j }。证明E是上下文无关语言。

*2.24 Let E = { a i b j | i j and 2 i j }. Show that E is a context-free language.

2.25 对于任何语言A,设SUFFIX ( A ) = { v : uv A对于某个单词u }。证明上下文无关语言的类由于SUFFIX操作而封闭。

2.25 For any language A let SUFFIX ( A ) = { v : uv A for some word u }. Show that the class of context-free languages ​​is closed under the operation SUFFIX .

2.26 证明如果G是乔姆斯基范式 CFG 文法,则对于每个长度n ≥ 1 的单词w L ( G ) ,任何推导w都需要 2 n – 1 个步骤。

2.26 Show that if G is a CFG in Chomsky normal form, then for every word w L ( G ) of length n ≥ 1, any derivation of w requires exactly 2n 1 steps.

*2.27G = ( V , Σ , R , STMT ) 为以下文法。

*2.27 Let G = ( V , Σ , R , STMT ) be the following grammar.

〈STMT〉分配 |​ 如果-那么 | 如果-那么-否则

STMT ASSIGN | IF-THEN | IF-THEN-ELSE

IF-THEN if 条件 then STMT

IF-THEN if condition then STMT

IF-THEN-ELSE if 条件 then STMT else STMT

IF-THEN-ELSE if condition then STMT else STMT

赋值 a:=1

ASSIGN a:=1

Σ = { if ,条件, then , else , a:=1 }

Σ = { if , condition , then , else , a:=1 }

V = { STMT , IF-THEN , IF-THEN-ELSE , ASSIGN }

V = { STMT , IF-THEN , IF-THEN-ELSE , ASSIGN }

G是一种编程语言的看似普通的语法,但它是有歧义的。

G is an ordinary-looking grammar of a portion of a programming language, but it is ambiguous.

a. 证明G是有歧义的。

a. Prove that G is ambiguous.

b. 为同一语言提供新的、明确的语法。

b. Provide a new, unambiguous grammar for the same language.

*2.28 为以下语言提供显式 CFG 语法。

*2.28 Provide unambiguous CFG grammars for the following languages.

a. { w:在每个前缀w 中,a出现的次数至少等于b出现的次数}

a. { w : in each prefix w the number of occurrences of a is at least equal to the number of occurrences of b }

b. { w :单词w中的数字a和数字b相等 }

b. { w : number a and number b in word w are equal }

c. { w : a在单词w中出现的次数至少等于b出现的次数}

c. { w : the number of occurrences of a in word w is at least equal to the number of occurrences of b }

*2.29 表明练习 2.9 中的语言A本质上是不明确的。

*2.29 Show that the language A from Exercise 2.9 is inherently ambiguous.

2.30 使用泵引理证明以下语言不是上下文无关的。

2.30 Use the pumping lemma to show that the following languages ​​are not context-free.

{ 0 n 1 n 0 n 1 n : n ≥ 0}

a. { 0 n 1 n 0 n 1 n : n ≥ 0}

{ 0 n #02 n #03 n : n 0 }

A b. { 0 n #02 n #03 n : n ≥ 0}

A c. { w # t : w是t 的子词,其中w , t { a , b } * }

A c. { w # t : w is a subword of t , where w , t { a , b } * }

d. { t 1 # t 2 # # t k : k ≥ 2, 每个t i { a , b } *t i = t j对于某些i j }

d. { t 1 # t 2 # # t k : k ≥ 2, each t i { a , b } * and t i = t j ​​for some i j }

2.31B是字母表 { 0 , 1 } 上包含相同数量的 0 和 1 的所有回文的语言。证明B不是上下文无关语言。

2.31 Let B be the language of all palindromes over the alphabet { 0 , 1 } containing equal numbers of zeros and ones. Prove that B is not a context-free language.

2.32Σ = {1, 2, 3, 4} 且C = { w Σ *:在单词w中,1出现的次数等于2出现的次数3出现的次数等于4 } 出现的次数。证明C不是上下文无关语言。

2.32 Let Σ = {1, 2, 3, 4} and C = { w Σ * : in a word w the number of occurrences of 1 is equal to the number of occurrences of 2 , and the number of occurrences of 3 is equal to the number of occurrences of 4 }. Prove that C is not a context-free language.

*2.33 证明F = { a i b j | i = kj对于某个正整数k } 不是上下文无关语言。

*2.33 Prove that F = { a i b j | i = kj for some positive integer k } is not a context-free language.

2.34 考虑语言B = L ( G ),其中G是练习 2.13 中提出的语法。上下文无关语言的泵浦引理(定理 2.34)表明语言B存在泵浦长度p 。在泵送引理中起作用的p的最小值是多少?证明你的答案合理。

2.34 Consider the language B = L ( G ), where G is the grammar given in Exercise 2.13. The pumping lemma for context-free languages ​​(Theorem 2.34) states the existence of a pumping length p for the language B . What is the minimal value of p that will work in the pumping lemma? Justify your answer.

2.35G是包含b变量的乔姆斯基范式CFG语法。证明如果G通过包含至少 2b 个步骤的推导生成某个单词,则语言L ( G ) 是无限的。

2.35 Let G be a CFG grammar in Chomsky normal form that contains b variables. Show that if G generates some word by a derivation involving at least 2b steps , then the language L ( G ) is infinite.

2.36 给出一个不是上下文无关但在泵引理中表现得像 CFL 的语言的例子。证明给出的例子有效。 (参见问题1.54中正则语言的类似示例。)

2.36 Give an example of a language that is not context-free but behaves like a CFL in the pumping lemma. Prove that the example works. (See the analogous example for regular languages ​​in Problem 1.54.)

*2.37 证明以下更强形式的泵引理,其中在划分单词s时, vy部分都必须非空。

*2.37 Prove the following stronger form of the Pumping Lemma in which both parts v and y must be nonempty when splitting a word s .

如果A是上下文无关语言,则存在一个数字k ,使得如果s是属于A且长度至少为k的任何单词,则s可以分为五部分,s = uvxyz满足条件:

If A is a context-free language, then there is a number k such that if s is any word in A of length at least k , then s can be split into five parts, s = uvxyz satisfying the conditions:

a. 对于每个i ≥ 0,uvxyz A

a. for all i ≥ 0, uv and xy and z A ,

b. v ε 且y ε,并且

b. v ε and y ε, and

| c。vxy | ≤ k

c. | vxy | ≤ k .

2.38问题 1.41 包含完美洗牌操作的定义。证明上下文无关语言的类在完美改组下不是封闭的。

A 2.38 Problem 1.41 contains the definition of the perfect shuffling operation. Show that the class of context-free languages ​​is not closed under perfect shuffling.

2.39 问题1.42 定义了洗牌操作。证明上下文无关语言的类不会因改组而封闭。

2.39 Problem 1.42 contains the definition of the shuffling operation. Show that the class of context-free languages ​​is not closed under shuffling.

*2.40如果属于一种语言的每个单词的所有前缀也属于该语言, 我们就说一种语言是前缀封闭的。设C是一种无限的、前缀封闭的、上下文无关的语言。证明C包含一个作为正则语言的无限子集。

*2.40 A language is said to be prefix-closed if all prefixes of every word belonging to the language also belong to the language. Let C be an infinite, prefix-closed, context-free language. Show that C contains an infinite subset that is a regular language.

*2.41任务 1.40 包含NOPREFIX ( A ) 和NOEXTEND ( A ) 操作 的定义。

*2.41 Task 1.40 contains the definitions of the operations NOPREFIX ( A ) and NOEXTEND ( A ).

a. 证明上下文无关语言的类没有因NOPREFIX操作而封闭。

a. Show that the class of context-free languages ​​is not closed under the NOPREFIX operation .

b. 证明上下文无关语言的类不是由于NOEXTEND操作而封闭的。

b. Show that the class of context-free languages ​​is not closed under the NOEXTEND operation .

*2.42Y ={ w : w = t 1 # t 2 # # t k对于k ≥ 0,每个t i1 *且每当i j时t it j }。在这种情况下,Σ = { 1 , # }。证明Y不是上下文无关语言。

*2.42 Let Y ={ w : w = t 1 # t 2 # # t k for k ≥ 0, every t i1 * and t it j , whenever i j }. In this case Σ = { 1 , # }. Prove that Y is not a context-free language.

2.43 对于单词w和 t ,如果单词w的符号是t中包含的符号的排列,我们将写成w t。换句话说,如果tw包含相同数量的相同符号,但顺序可能不同,则w t 。

2.43 For words w and  t we will write w t if the symbols of w are a permutation of the symbols that constitute t . In other words, w t if t and w contain the same symbols in the same number, but possibly in a different order.

对于任何单词w,我们定义SCRAMBLE ( w ) = { t : t w }。对于任何语言 A,SCRAMBLE ( A ) = { t : t SCRAMBLE ( w ) 对于某些w A }。

For any word w we define SCRAMBLE ( w ) = { t : t w }. For any language  A let SCRAMBLE ( A ) = { t : t SCRAMBLE( w ) for some w A }.

a. 证明如果Σ = { 0 , 1 },则正则语言的SCRAMBLE是上下文无关语言。

a. Show that if Σ = { 0 , 1 }, then SCRAMBLE for a regular language is a context-free language.

b. 如果(a) 中Σ包含三个或更多符号,会发生什么情况?证明你的答案。

b. What happens if Σ contains three or more symbols in part (a)? Prove your answer.

2.44 如果A和 B是语言,我们定义A B = { xy : x Ay B且 | x | = | y |}。证明如果A和 B是正则语言,则A B是 CFL。

2.44 If A and  B are languages, we define A B = { xy : x A and y B and | x | = | y |}. Show that if A and  B are regular languages, then A B is a CFL language.

*2.45A = { wtw R : w , t { 0 , 1 } * i || = | t |}。证明A不是 CFL 语言。

*2.45 Let A = { iff R : w , t { 0 , 1 } * and | w | = | t |}. Prove that A is not a CFL language.

2.46 考虑以下 CFG G语法:

2.46 Consider the following CFG grammar G :

S SS |时间

S SS | T

T a T b | ab

T a T b | ab

描述语言L ( G ) 并证明该文法是二义性的。给出H 的唯一语法,使得L ( H ) = L ( G ) 以及H唯一的证明草图。

Describe the language L ( G ) and show that this grammar is ambiguous. Give an unambiguous grammar H such that L ( H ) = L ( G ) and a sketch of a proof that H is unambiguous.

2.47Σ = {0,1} 并令B为后半部分至少包含一个符号1​​ 的单词集合。换句话说,B = { uv : u Σ *, v Σ *1 Σ * i || ≥| v |}。

2.47 Let Σ = {0,1} and let B be the set of words containing at least one 1 in the second half. In other words, B = { uv : u Σ *, v Σ *1 Σ * and | u | ≥ | v |}.

a.提出一个可识别B 的 PDA 。

a. Propose a PDA that recognizes B.

b.提出生成B 的 CFG 语法。

b. Propose a CFG grammar that generates B .

2.48Σ = {0,1} 并令C 1为所有符号中间三分之一包含1 的单词的语言。令C 2为所有在其符号的中间三分之一中包含两个1 的单词的语言。因此C 1 = { xyz : x , z Σ * 且y Σ *1 Σ *,其中 | x | = || ≥| y |} 且C 2 = { xyz : x , z ε Σ * 且y ε Σ *1 Σ *1 Σ *,其中 | x | = || ≥| y |}。

2.48 Let Σ = {0,1} and let C 1 be the language of all words containing 1 in their middle third of symbols. Let C 2 be the language of all words containing two 1s in their middle third of symbols. So C 1 = { xyz : x , z Σ * and y Σ *1 Σ *, where | x | = | z | ≥ | y |} and C 2 = { xyz : x , z Σ * and y Σ *1 Σ *1 Σ *, where | x | = | z | ≥ | y |}.

a. 证明C 1是CFL 语言。

a. Prove that C 1 is a CFL language.

b. 证明C 2不是 CFL。

b. Show that C2 is not a CFL language.

*2.49我们在第一章中将 语言A的旋转闭包定义为RC ( A ) = { yx : xy A }。证明上下文无关语言的类由于旋转闭包而封闭。

*2.49 The rotational closure of a language A was defined in Chapter 1 as RC ( A ) = { yx : xy A }. Show that the class of context-free languages ​​is closed under rotational closure.

*2.50我们将语言A的CUT 操作定义为CUT ( A ) = { yxz : xyz A }。证明上下文无关语言的类相对于CUT不是封闭的。

*2.50 We have defined the CUT operation of language A as CUT ( A ) = { yxz : xyz A }. Show that the class of context-free languages ​​is not closed under CUT .

2.51 证明每个DCFG文法都是唯一的CFG文法。

2.51 Prove that every DCFG grammar is a unique CFG grammar.

A* 2.52 证明每个 DCFG 语法都会生成后缀语言。

A* 2.52 Prove that every DCFG grammar generates a suffix language.

*2.53 证明确定性上下文无关语言的类由于以下操作而不是封闭的:

*2.53 Show that the class of deterministic context-free languages ​​is not closed under the following operations:

总和

a. Total

交叉口

b. Intersection

连接

c. Concatenation

d. 克莱内闭包

d. Kleene's Closure

e. 逆转

e. Reversal

2.54G为以下文法:

2.54 Let G be the following grammar:

ST TT a P b | T b M a | ε PPaP b | ε MM b M a | ε

ST TT a P b | T b M a | ε PPaP b | ε MM b M a | ε

a. 证明L ( G ) = { w : w包含相同数量的符号a和 b }。对中的单词长度使用归纳证明。

a. Prove that L ( G ) = { w : w contains equal numbers of symbols a and  b }. Use a proof by induction on the length of the word w .

b. 使用DK检验证明G是DCFG文法。

b. Use the DK test to show that G is a DCFG grammar.

c.描述识别L ( G ) 的 DPDA 。

c. Describe DPDA recognizing L ( G ).

2.55G 1为我们在例 2.45 中介绍的语法。使用DK检验证明G 1不是DCFG文法。

2.55 Let G 1 be the grammar we introduced in Example 2.45. Use the DK test to show that G 1 is not a DCFG grammar.

R S |时间

R S | T

S a S b | ab

S a S b | ab

T a T bb |艾布

T a T bb | abb

*2.56A = L ( G 1 ),其中G 1在问题 2.55 中定义。证明A不是 DCFL 语言。 (提示:假设A是一个 DCFL,并考虑相应的 DPDA P。修改P使其输入字母表为 { a , b , c }。当这台机器第一次进入接受状态时,它假装从此时开始输入, c 的符号是b的符号。什么语言会接受这样修改后的P自动机?)

*2.56 Let A = L ( G 1 ), where G 1 was defined in Problem 2.55. Prove that A is not a DCFL language. (Hint: Assume that A is a DCFL language, and consider the corresponding DPDA P . Modify P so that its input alphabet is { a , b , c }. When it first enters the accepting state, it pretends that from that point on the input symbols c are symbols b . What language would accept such a modified P ?)

*2.57B = { a i b j ck : i , j , k ≥ 0 且i = ji = k }。证明B不是 DCFL 语言。

*2.57 Let B = { a i b j c k : i , j , k ≥ 0 and i = j or i = k }. Prove that B is not a DCFL language.

*2.58C = { ww R : w {0,1} * }。证明C不是DCFL语言。 (提示:假设当某个 DPDA P运行在状态qx位于其堆栈顶部时,则P永远不会从堆栈中弹出x以下的任何内容,无论它从那里读取什么输入字。在这种情况下,此时P堆栈的内容对其后续行为没有影响,因此该行为只能依赖于qx。)

*2.58 Let C = { ww R : w {0,1} * }. Prove that C is not a DCFL language. (Hint: Suppose that when a certain DPDA P is started in state q with symbol x on top of its stack, then P never pops anything below x , no matter what input word it reads from that point. In such a case, the contents of P 's stack at that point have no effect on its subsequent behavior, so its behavior can only depend on q and x .)

*2.59 如果我们排除上下文无关语法中的 ε-产生式,我们可以简化DK测试。在测试的简化版本中,我们只需要检查每个DK接受状态是否包含单个产生式。证明没有 ε-产生式的 CFG 语法当且仅当它属于 DCFG 类时通过简化的DK测试。

*2.59 If we exclude ε-productions in context-free grammars, we can simplify the DK test . In the simplified version of the test, we only need to check that each state accepting DK contains a single production. Prove that a CFG grammar without ε-productions passes the simplified DK test if and only if it is of class DCFG.

2.60Σ = { 0 , 1 , # }。令C = { x # x R # x : x { 0 , 1 } * }。证明C是CFL。

2.60 Let Σ = { 0 , 1 , # }. Let C = { x # x R # x : x { 0 , 1 } * }. Prove that C is a CFL language.

精选解决方案

Selected solutions

2.3 (a) RXST; ( b )a、b; ( c ) R; ( d )属于L ( G )的三个词是abbaaab; ( e )不属于L ( G )的三个词是ab和ε; ( f ) 错误; ( g ) 真相; ( h ) 错误; (一) 真相; ( j ) 真相; ( k ) 错误; ( l ) 真相; ( m ) 真相; ( n ) 错误; (o) L ( G ) 由a和 b之上的所有非回文单词组成。

2.3 (a) R , X , S , T ; ( b ) a, b ; ( c ) R ; ( d ) The three words that belong to L ( G ) are ab , ba , and aab ; ( e ) The three words that do not belong to L ( G ) are a , b , and ε; ( f ) False; ( g ) True; ( h ) False; (i) True; ( j ) True; ( k ) False; ( l ) True; ( m ) True; ( n ) False; (o) L ( G ) consists of all the words over a and  b that are not palindromes.

2.4 (a) S R 1 R 1 R 1 R (d) S 0 | 0 S 0 | 0 0 S 1 | 0 1 S 0 | 11

2.4 (a) S R 1 R 1 R 1 R (d) S 0 | 0 S 0 | 0 S 1 | 1 S 0 | 1 S 1

R 0 R | 1 R | ε

R 0 R | 1 R | ε

2.6 (a) S TT

(c)
S TX

2.6 (a) S T and T

(c)
S TX

T TT |一个T b | b T a |一个 | ε T 0 T 0 | 11 | #X

T TT | a T b | b T a | a | ε T 0 T 0 | 1 T 1 | #X

X 0 X | 10 月1日| ε

X 0 X | 1 X | ε

T生成所有包含至少与b一样多的a 的单词,然后S强制添加一个额外的a'

T generates all words containing at least as many a s as b , after which S forces an additional a .

2.7 (a) PDA 使用其堆栈来计算符号a的数量与符号b的数量 之间的差异。只要该计数器为正,就进入接受状态。更详细地说,其工作原理如下。 PDA 审查输入数据。如果它注意到b并且堆栈顶部的符号是a ,则会从堆栈中删除该a 。类似地,如果它注意到a并且堆栈顶部的符号是b,则会将其从堆栈中删除。在任何其他情况下,它将输入符号压入堆栈。处理输入数据后,如果a位于堆栈顶部,则自动机接受输入。在其他情况下,他会拒绝它们。

2.7 (a) A PDA uses its stack to count the difference between the number of symbols a and the number of symbols b . It enters the accepting state whenever this counter is positive. More specifically, it works as follows. The PDA scans the input. If it sees b and the symbol at the top of the stack is a , it pops a from the stack. Similarly, if it sees a and the symbol at the top of the stack is b , it pops it from the stack. Otherwise, it pushes the input symbol onto the stack. After it has finished processing the input, if a is at the top of the stack , the machine accepts the input. Otherwise, it rejects it.

( c ) PDA 浏览输入字并将每个符号压入堆栈,直到读取到# 如果序列a #从未出现,它将丢弃输入单词。然后,PDA 会跳过一些输入,不确定地选择在哪里停止跳过。从这一点开始,它将后续输入符号与从堆栈中弹出的符号进行比较。如果出现任何不匹配,或者如果输入字在堆栈不为空时完成,则该计算路径将丢弃该输入。如果堆栈变空,机器将读取其余的输入并接受它。

( c ) The PDA looks at the input word and pushes each symbol onto the stack until it reads a # . If the sequence a # never appears, it discards the input word. The PDA then skips some of the input, nondeterministically choosing where to stop skipping. From that point on, it compares subsequent input symbols with the symbols popped from the stack. On any mismatch, or if the input word terminates while the stack is not empty, this path of computation discards the input. If the stack becomes empty, the machine reads the rest of the input and accepts.

2.8 这是一个推导:

2.8 Here is one derivation:

句子 名词短语〉〈动词短语

CMPLX-名词〉〈动词短语

文章〉〈名词〉〈动词短语

名词〉动词短语

那个女孩动词短语

少女 CMPLX-动词〉〈预备短语

少女动词〉〈名词短语〉预备短语

少女触及名词短语〉〈预备短语

女孩触及 CMPLX-名词〉〈准备短语

女孩触及文章〉〈名词〉 准备短语

女孩触及名词〉〈准备短语 〉 → 女孩触及 〈 准备短语

女孩触及男孩准备-PH RACE

女孩用 PREP 〉〈 CMPLX-NOUN 〉触碰男孩

女孩用 CMPLX-NOUN 〉触碰男孩

女孩用 ARTICLE 〉 〈 NOUN 〉触碰男孩

女孩用〈 〈 NOUN 〉 触碰男孩名词

女孩用花触摸男孩

SENTENCE NOUN-PHRASE 〉〈 VERB-PHRASE

CMPLX-NOUN 〉〈 VERB-PHRASE

ARTICLE 〉〈 NOUN 〉〈 VERB-PHRASE

The NOUN 〉〈 VERB-PHRASE

The girl VERB-PHRASE

The girl CMPLX-VERB 〉〈 PREP-PHRASE

The girl VERB 〉〈 NOUN-PHRASE 〉〈 PREP-PHRASE The girl

touches NOUN​〉〈 PREP-PHRASE The girl touches the boy PREP-PHRASE The girl touches the boy PREP 〉〈 CMPLX-NOUN The girl touches the boy with CMPLX-NOUN The girl touches the boy with ARTICLE 〉〈 NOUN The girl touches the boy with the NOUN The girl touches the boy with the flower

















这是另一个左手推导:

Here is another left-hand derivation:

句子 名词短语〉〈动词短语

CMPLX-名词〉〈动词短语

文章〉〈名词〉〈动词短语

名词〉动词短语

那个女孩动词短语

女孩 CMPLX-动词

女孩动词〉〈名词短语

女孩触动名词短语

女孩触动 CMPLX-名词〉〈预备短语

女孩触摸文章〉〈名词〉〈准备短语〉 女孩

触摸名词〉〈准备短语

女孩触摸男孩准备短语

女孩触摸男孩准备〉〈 CMPLX-名词

女孩用 CMPLX-名词〉触碰男孩

女孩用文章〉〈名词〉触碰男孩

女孩用名词〉触碰男孩

女孩用花触碰男孩

SENTENCE NOUN-PHRASE 〉〈 VERB-PHRASE

CMPLX-NOUN 〉〈 VERB-PHRASE

ARTICLE 〉〈 NOUN 〉〈 VERB-PHRASE

The NOUN 〉〈 VERB-PHRASE

The girl VERB-PHRASE

The girl CMPLX-VERB

The girl VERB 〉〈 NOUN-PHRASE

The girl touches NOUN-PHRASE

The girl touches CMPLX-NOUN 〉〈 PREP-PHRASE

The girl touches ARTICLE 〉〈 NOUN 〉 PREP- PHRASE

The girl touches the NOUN 〉〈 PREP-PHRASE

The girl touches the boy PREP-PHRA SE〉

The girl touches the boy PREP 〉〈 CMPLX-NOUN

The girl touches the boy with CMPLX-NOUN

The girl touches the boy with ARTICLE 〉〈 NOUN

The girl touches the boy with the NOUN

The girl touches the boy with the flower

这些派生词中的每一个都对应于英语中的不同含义。在句子的第一个推导中,这意味着女孩触摸男孩。在第二个推导中,男孩拿着花,女孩触摸花。

Each of these derivations corresponds to a different meaning in English. In the first derivation, the sentence means that the girl used the flower to touch the boy . In the second derivation, the boy is holding the flower when the girl touches him.

2.18 ( a ) 设C为上下文无关语言,R为正则语言。设P为识别C语言的PDA ,D为识别R语言的DFA 。设 Q 为状态P的集合,Q'为状态D的集合;我们构造一个识别语言C R 的PDA P',使其状态集为Q × Q'P'将执行与P相同的操作,并且还会跟踪D的状态。当且仅当它以状态q F P × F D结束时,它才会接受单词w,其中F P是接受P 的状态集,FD是接受D的状态集。由于C RP'识别,因此该语言是上下文无关的。

2.18 ( a ) Let C be a context-free language and R a regular language. Let P be a PDA recognizing language C , and D be a DFA recognizing language R . Let Q be the set of states of P and Q' the set of states of D ; we construct a PDA P' recognizing language C R such that its set of states is Q × Q' . P' will perform the same operations as P , and additionally will keep track of the states of D . It will accept a word w if and only if it terminates in state q F P × F D , where F P is the set of states accepting P and F D is the set of states accepting D . Since C R is recognized by P' , this language is context-free.

( b ) 令R为正则语言a*b*c*。如果A是 CFL,则由 (a) 语言A R也将是 CFL。然而,A R = { a n b n c n : n ≥ 0},并且在例 2.36 中我们证明了语言A R不是上下文无关的。因此,A不是 CFL 语言。

( b ) Let R be a regular language a*b*c* . If A were a CFL language, then by (a) the language A R would also be a CFL language. However, A R = { a n b n c n : n ≥ 0}, and in Example 2.36 we proved that the language A R is not context-free. Hence, A is not a CFL language.

2.30 ( b ) 令B = { 0 n #0 2 n #0 3 n : n ≥ 0}。令p为由泵浦引理得出的泵浦长度。令s = 0 p #0 2 p #0 3 p。我们将证明单词s = uvxyz不能被泵浦。

2.30 ( b ) Let B = { 0 n #0 2 n #0 3 n : n ≥ 0}. Let p be the pumping length resulting from the pumping lemma. Let s = 0 p #0 2 p #0 3 p . We show that the word s = uvxyz cannot be pumped.

vy都不能包含#,否则uv 2 xy 2 z将包含两个以上的#符号。因此,如果我们根据位置#将s分为三段: 0 p、 0 2 p和 0 3 p,则这些段中至少有一个不包含在vy中。因此uv 2 xy 2 z不属于B,因为段长度比 1 : 2 : 3 未保留。

Neither v nor y can contain # , since otherwise uv 2 xy 2 z would contain more than two # symbols . Thus, if we divide s into three segments by position # : 0 p , 0 2 p , and 0 3 p , at least one of these segments is not contained in either v or w y . Hence uv 2 xy 2 z does not belong to B , since the 1 : 2 : 3 proportion of the segment lengths is not preserved.

( c ) 令C = { w # t : w是t的子词,其中w , t { a , b } * }。令p为泵送引理产生的长度。我们假设s = a p b p #a p b p。我们将证明单词uvxyz不能被泵浦。

( c ) Let C = { w # t : w is a subword of t , where w , t { a , b } * }. Let p be the length resulting from the pumping lemma. Assume s = a p b p #a p b p . We will show that the word uvxyz cannot be pumped.

vy都不能包含#,否则uv 0 xy 0 z将不包含符号#,因此不属于C。如果vy都出现在#的左侧,则单词uv 2 xy 2 z不能属于C,因为#左侧的部分比右侧的部分长。类似地,如果两个单词都出现在#符号的右侧,则单词uv 0 xy 0 z不能属于C,因为 # 左侧的部分比右侧的部分长。如果vy之一为空(它们不能都为空),我们将其视为它们都出现在#符号的同一侧,如上所述。

Neither v nor y can contain # , since otherwise uv 0 xy 0 z would not contain # , and hence would not belong to C . If v and y both occur to the left of # , the word uv 2 xy 2 z cannot belong to C , since its part to the left of # is longer than its right. Similarly, if both words occur to the right of # , the word uv 0 xy 0 z cannot belong to C , since again its part to the left of # is longer than its right. If one of v and y is empty (they cannot both be empty at the same time), we treat it as if they both occurred on the same side of # , as above.

唯一剩下的情况是vy都非空并且位于#符号的不同一侧。然而,由于泵引理 | 的第三个条件,v仅包含b,并且y仅包含 a 符号。vxy | ≤ p。由此可见uv 2 xy 2 z在#号左边包含了更多的b符号,因此它不能属于C。

The only remaining case is when both words v and y are nonempty and appear on different sides of the symbol # . However, then v contains only b symbols and y contains only a symbols by the third condition of the Pumping Lemma | vxy | ≤ p . It follows that uv 2 xy 2 z contains more b symbols on the left side of the # , and so cannot belong to C .

2.38A为语言 { 0 k 1 k : k ≥ 0},B为语言 { a k b 3 k : k ≥ 0}。A和 B的理想改组是语言C = {( 0a ) k ( 0b ) k ( 1b ) 2 k : k ≥ 0}。很容易证明语言A和 B属于 CFL 类,但C不属于此类,正如我们现在将要证明的那样。假设 C 属于 CFL 类,令p为泵引理产生的泵长度,s为单词 ( 0a ) p ( 0b ) p ( 1b ) 2 p。由于s的长度大于ps C,因此我们可以将s表示为s = uvxyz,满足引理的三个条件。属于C的单词恰好包含字符a的四分之一和八分之一。为了使单词uv 2 xy 2 z具有此属性,单词vxy必须同时包含符号1a。然而,这是不可能的,因为字符 1a在单词s中被 2 个p符号分隔,即使第三个条件规定 | vxy | ≤  p。所以C不是上下文无关语言。

2.38 Let A be the language { 0 k 1 k : k ≥ 0} and B the language { a k b 3 k : k ≥ 0}. An ideal shuffle of A and  B is the language C = {( 0a ) k ( 0b ) k ( 1b ) 2 k : k ≥ 0}. It is easy to show that the languages ​​A and  B are of class CFL, but C is not of class CFL, as we will show. Suppose C is of class CFL and let p be the pumping length implied by the Pumping Lemma and s be the word ( 0a ) p ( 0b ) p ( 1b ) 2 p . Since the length of s is greater than p and s C , we can represent s as s = uvxyz , satisfying the three conditions of the lemma. The words of C contain exactly one-fourth the characters of ones and one-eighth the characters of a . For the word uv 2 xy 2 z to have this property, the word vxy must contain both the symbols 1 and a . However, this is impossible, since the symbols  1 and a are separated by 2p symbols in the word s , even though the third condition states that | vxy | ≤  p . So C is not a context-free language.

2.52 我们将使用间接证明。假设w和 wz是属于L ( G ) 的两个不等词,其中G是 DCFG 语法。它们都是有效的单词,因此它们都有句柄,并且这些句柄必须匹配,因为我们可以写w = xhywz = xhyz = xhŷ,其中h是w 的句柄。由此可见,w和 wz的第一个归约步骤分别产生正确的单词u和 uz。我们可以继续这个过程,直到获得S 1S 1 z,其中S 1是初始变量。然而,S 1不会出现在任何产生式的右侧,因此我们不能从 中减少单词S 1,这就产生了矛盾。

2.52 We will use an indirect proof. Suppose w and  wz are two unequal words belonging to L ( G ), where G is a DCFG. Both are valid words, so both have handles, and these handles must match, since we can write w = xhy and wz = xhyz = xhŷ , where h is a handle on w . It follows that the first reduction steps for w and  wz produce valid words u and  uz , respectively . We can continue this process until we obtain S 1 and S 1 z , where S 1 is the initial variable. However, S 1 does not occur on the right-hand side of any production, so we cannot reduce S 1 to , which gives a contradiction.

3

丘奇-图灵假说

3

The Church-Turing Hypothesis

到目前为止,在发展计算理论的过程中,我们已经提出了几种计算设备的模型。有限状态机对于内存较小的设备来说是很好的模型。堆栈机对于具有无限内存的设备来说是很好的模型,但根据后进先出规则,仅以堆栈的形式存在。我们还表明,一些非常简单的任务超出了这些模型的能力。因此,它们的局限性太大,无法作为通用计算机的模型。

So far, in the course of developing the theory of computation, we have presented several models of computing devices. Finite-state machines are good models for devices with a small amount of memory. Stack automata are good models for devices that have infinite memory, but only in the form of a stack, according to the last-in, first-out rule. We have also shown that certain very simple tasks are beyond the capabilities of these models. They are therefore too limited to serve as models of general-purpose computers.

3.1

图灵机

3.1

Turing Machines

我们现在转向一个更高效的模型,该模型由艾伦·图灵于 1936 年首次提出,称为图灵机。图灵机与有限状态机类似,但具有无限和无限的内存,是通用计算机的更忠实模型。图灵机可以做真正计算机能做的一切。然而,即使是图灵机也无法解决某些问题。事实上,这些问题超出了计算的理论极限。

We now turn to a much more powerful model, first proposed by Alan Turing in 1936, called the Turing machine . Similar to a finite state machine but with infinite and unbounded memory, the Turing machine is a more faithful model of a general-purpose computer. A Turing machine can do anything that real computers can do. However, even a Turing machine cannot solve some problems. In fact, these problems lie beyond the theoretical limits of computation.

图灵机模型使用无限磁带作为其无限内存。它配备有一个磁头,可以读写符号并沿着磁带移动。最初,磁带仅包含输入单词,其他地方为空白。当机器需要存储信息时,它可以将其写入磁带。要读取存储的信息,他可以将头移回这个地方。机器继续运行,直到决定返回结果。接受或拒绝是通过进入指定的接受或拒绝状态来实现的。如果机器不进入接受或拒绝状态,它将永远运行,永不停止。

The Turing machine model uses an infinite tape as its infinite memory. It has a head that can read and write symbols and move along the tape. Initially, the tape contains only the input word, and is blank everywhere else. When the machine needs to store information, it can write it to the tape. To read the written information, it can move its head back to that location. The machine continues to operate until it decides to return a result. Acceptance or rejection is achieved by entering designated accepting or rejecting states. If the machine does not enter an accepting or rejecting state, it will run forever, never stopping.

3.1

图灵机示意图

Figure 3.1

Turing machine diagram

以下列表总结了有限状态机和图灵机之间的差异。

The following list summarizes the differences between finite-state machines and Turing machines.

  1. 图灵机既可以从磁带上写入符号,也可以从磁带上读取符号。
  2. A Turing machine can both write and read symbols from the tape.
  3. 读/写头可以左右移动。
  4. The read/write head can move both left and right.
  5. 磁带是无穷无尽的。
  6. The tape is infinite.
  7. 特殊拒绝或接受状态立即生效。
  8. Special states of rejection or acceptance take immediate effect.

我们现在将展示图灵机M 1测试与语言B = { w # w : w { 0 , 1 }*} 的隶属关系。如果输入单词是B的元素,我们希望M 1接受,否则拒绝。为了更好地理解M 1 的工作原理,让我们设身处地地想像我们正站在一个由数百万个字符组成的一英里长的输入单词上。我们的目标是确定这个输入是否属于B - 也就是说,我们要检查输入是否由两个由#符号分隔的相同单词组成。输入的内容太长,我们无法记住,但我们可以在单词上来回移动并在其上放置标记。显而易见的策略是在#符号两侧的相应空格之间进行锯齿形查找,并确定它们是否匹配。我们在磁带上放置标记,以便我们可以跟踪彼此对应的位置。

We now introduce a Turing machine M 1 that tests for membership in the language B = { w # w : w { 0 , 1 }*}. We want M 1 to accept if the input is a member of B , and reject otherwise. To better understand how M 1 works , let's put ourselves in its shoes, imagining that we are standing on a mile-long input word of millions of characters. Our goal is to determine whether the input is a member of B —that is, we want to check whether the input consists of two identical words separated by the symbol # . The input is too long for us to remember, but we can move back and forth across the word and place markers on it. An obvious strategy is to zigzag between the corresponding places on either side of the symbol # and determine whether they match. We place markers on the tape so that we can keep track of the places that match each other.

我们将设计M 1来实现上述想法。它对输入字执行多次读/写头传递。在每遍中,匹配#符号每一侧的一个字符。为了跟踪哪些符号已经被检查过,M 1在每个符号被检查后划掉它。如果划掉所有符号,则表示匹配成功,M 1进入接受状态。如果它检测到不匹配,则会进入拒绝状态。综上所述,机器M 1的算法如下。

We design M 1 to implement the above idea. It makes multiple passes of the read/write head through the input word. On each pass, it matches one of the characters on each side of the symbol # . To keep track of which symbols have already been checked, M 1 crosses out each symbol after checking it. If it crosses out all the symbols, it means that everything was successfully matched, and M 1 moves to the accepting state. If it detects a mismatch, it moves to the rejecting state. To summarize, the algorithm for M 1 is as follows.

M 1 =“对于输入字:

M 1 = "For input word in :

  1. 沿着胶带曲折到#符号两侧的匹配位置,看看这些位置是否包含相同的符号。如果没有,或者没有找到#符号,则丢弃。划掉选中的符号以了解哪些符号彼此匹配。
  2. Zigzag along the tape to the matching positions on either side of the # symbol to see if the positions contain the same symbol. If not, or if no # symbol is found , reject . Cross out the checked symbols to see which symbols correspond.
  3. 将#左侧的所有符号都划掉后,检查#右侧是否有任何未选中的符号。如果还有任何符号,则丢弃;否则接受。”
  4. Once all symbols to the left of # have been crossed out, check if there are any unchecked symbols to the right of # . If any symbols remain, reject ; otherwise, accept ."

下图显示了M 1机器计算输入字011000#011000的几个快照(即磁带内容和磁头位置的表示) 。

The figure below shows several snapshots (i.e. representations of the tape contents and head position) from the computation of machine M 1 for the input word 011000#011000 .

3.2输入字 011000#011000图灵机M 1

计算的快照

Figure 3.2

Snapshots of the computation of the Turing machine M 1 for the input word 011000#011000

M 1图灵机的描述概述了它的工作原理,但没有提供所有细节。我们可以正式描述图灵机,提供类似于有限和堆叠自动机情况的所有细节。该描述指定了图灵机正式定义的每个部分,我们稍后将介绍。然而实际上,我们几乎从不给出图灵机的正式描述,因为它们非常广泛。

This description of the Turing machine M 1 is a sketch of its operation, but it does not give all the details. We can describe Turing machines formally, giving all the details, in an analogy to the case of finite-state machines and pushdown automata. Such a description specifies every part of the formal definition of a Turing machine, which we will present in a moment. In reality, however, we almost never give formal descriptions of Turing machines, because they are so extensive.

图灵机的正式定义

Formal definition of a Turing machine

图灵机定义的核心是转换函数δ,因为它决定了机器如何从一种状态转移到下一种状态。在图灵机的情况下,δ 的形式为:Q × Г Q × Г ×{ L , R }。因此,当机器处于特定状态q并且其磁头位于包含符号a 的磁带字段上方并且如果 δ( q , a ) = ( r , b , L ) 时,机器将写入符号b,替换a,然后进入状态第三个分量是LR - 表示录音后磁头是否向左或向右移动。在此示例中,L表示向左移动。

The heart of the definition of a Turing machine is the transition function δ, since it governs how the machine gets from one state to the next. In the case of a Turing machine, δ takes the form Q × Γ Q × Γ ×{ L , R }. So, when the machine is in a particular state q and its head is over a field of the tape containing symbol a , and if δ( q , a ) = ( r , b , L ), then the machine writes symbol b , replacing a , and then moves to state r . The third component is either L or R , which denotes whether the head moves left or right after writing. In this example, L denotes left.

定义 3.3

Definition 3.3

图灵机是一个有序的七元组(7元组),( Q , Σ , Γ , δ, q 0 , q Accept , qject),其中Q , Σ , Γ是有限集

A Turing machine is an ordered seven (7-tuple), ( Q , Σ , Γ , δ, q 0 , q accept , q reject ), where Q , Σ , Γ are finite sets and

  1. Q是状态集,
  2. Q is a set of states,
  3. Σ是输入字母表,不包含空符号
  4. Σ is the input alphabet, not containing the empty symbol ,
  5. Г是磁带字母表,使得 ε ГΣ Г
  6. Γ is a tape alphabet such that Γ and Σ Γ ,
  7. δ : Q × Г Q × Г × { L , R } 是过渡函数,
  8. δ : Q × Γ Q × Γ × { L , R } is the transition function,
  9. q 0 Q是初始状态,
  10. q 0 Q is the initial state,
  11. q Accept Q是接受状态,
  12. q accept Q is an accepting state,
  13. qreject Q 是拒绝状态其中qreject qaccept
  14. q reject Q is a rejecting state, with q reject q accept .

图灵机M = ( Q , Σ , Γ , δ, q 0 , q Accept , q Reject ) 执行如下计算。最初,M在磁带最左边的字段中接收其输入字w = w 1 w 2 … w n Σ *,而磁带的其余部分是空的(即填充有空符号)。磁头从最左边的磁带区开始。请注意,Σ不包含空白符号,因此磁带上出现的第一个此类符号表示输入字的结尾。一旦M开始,计算就遵循转换函数描述的规则。如果M尝试将磁头移动到磁带左端的左侧,则即使转换函数发出L信号,磁头在这次移动中仍保持在相同位置。计算持续进行,直到机器进入接受或拒绝状态,然后停止。如果这些事件都没有发生,M将无限期地运行。

A Turing machine M = ( Q , Σ , Γ , δ, q 0 , q accept , q reject ) computes as follows. Initially, M receives its input word w = w 1 w 2 … w n Σ * on the leftmost fields of the tape, and the rest of the tape is empty (i.e. filled with null symbols). The head starts at the leftmost field of the tape. Note that Σ does not contain a null symbol, so the first such symbol that appears on the tape indicates the end of the input word. Once M is started , the computation proceeds according to the rules described by the transition function. If M ever tries to move the head to the left of the left end of the tape, the head stays in that position during that move, even if the transition function signals L . Computation continues until the machine enters an accepting or rejecting state, at which point it stops. If neither of these events occurs, M runs forever.

在执行计算时,当前状态、磁带的当前内容以及磁头的当前位置都会发生变化。这三个元素的集合称为图灵机配置。配置通常以特殊方式呈现。对于状态q和磁带字母Γ上方的两个单词uv,我们将uqv写为一种配置,其中当前状态为q,磁带的当前内容为uv,当前磁头位置是磁带字母表的第一个符号。词v .在单词v 的最后一个符号之后,磁带仅包含空符号。例如,1011 q 7 01111表示磁带内容为101101111、当前状态为q 7且头部当前位于第二个0 的配置。图 3.4 显示了此配置中的图灵机。

During the computation, the current state, the current contents of the tape, and the current location of the head change. The set of these three elements is called the Turing machine configuration . Configurations are often represented in a special way. For a state q and two words u and v over the tape alphabet Γ, we write uqv as a configuration in which the current state is q , the current contents of the tape is uv , and the current location of the head is the first symbol of word v . After the last symbol of word v , the tape contains only null symbols. For example, 1011 q 7 01111 represents a configuration in which the contents of the tape are 101101111 , the current state is q 7 , and the head is currently at the second 0 . Figure 3.4 shows the Turing machine in this configuration.

3.4

图灵机配置 1011 q 7 01111

Figure 3.4

Turing machine in configuration 1011 q 7 01111

我们现在将形式化图灵机如何执行计算的直观想法。如果机器能够一步正确地从C 1转到C 2 ,我们会说配置C 1 导致配置C 2。我们正式定义这个概念如下。

We now formalize the intuitive notion of how a Turing machine performs a computation. We will say that a configuration C 1 leads to a configuration C 2 if the machine can correctly go from C 1 to C 2 in a single step . We formally define this notion as follows.

假设我们有abc属于Γuv属于Γ * ,并且状态q iq j。在这种情况下,ua qbv以及uq j acv是两种配置。我们这么说

Suppose we have a , b and c belonging to Γ , and u and v belonging to Γ * and states q i and q j . In that case ua q i bv and uq j acv are two configurations. We say that

ua qbv导致uq j acv

ua q and bv leads to uq j acv

如果 δ( q i , b ) = ( q j , c , L )。这处理图灵机向左移动的情况。对于向右运动,我们说

if δ( q i , b ) = ( q j , c , L ). This handles the case when the Turing machine makes a move to the left. For a move to the right, we say that

ua q i bv导致uac q j v

ua q and bv leads to uac q j v

如果 δ( q i , b ) = ( q j , c , R )。

if δ( q i , b ) = ( q j , c , R ).

当头部位于配置的一端时,我们需要考虑特殊情况。对于左端,当转换函数命令向左移动时, qbv的配置要么导致q j cv(因为我们不允许机器移动超出磁带的最左端),要么导致cq j v用于向右运动。在右端的情况下,配置ua q i等价于ua q i ,因为我们假设除了配置中表示的磁带部分之外,只有空符号。因此,我们可以像以前一样处理这种情况,即磁头不在磁带的右端。

When the head is at one end of the configuration, we have special cases to consider. For the left end, the configuration q i bv either leads to q j cv when the transition function dictates a leftward movement (since we do not allow the machine to move beyond the leftmost end of the tape), or it leads to cq j v for a rightward movement. For the right end, the configuration ua q i is equivalent to ua q i , since we have assumed that there are only empty symbols outside the part of the tape represented in the configuration. We can therefore handle this case as before, when the head is not at the right end of the tape.

初始配置 M对于输入字w是配置q 0 w,这表明机器处于初始状态q 0并且其磁头位于磁带上的最左边位置。在接受配置中,该配置的状态是q Accept。在拒绝配置中,配置状态为q拒绝。接受和拒绝配置是最终配置,不会导致进一步的配置。由于机器被定义为在状态q接受q拒绝时停止,因此我们可以等效地以更复杂的形式 δ 定义传递函数: Q' × Г Q × Г × { L , R },其中Q '是一个没有状态q Acceptq Reject 的集合Q。如果存在一系列配置C 1 , C 2 , … , C k ,则图灵机M接受输入使得

The initial configuration of M for input word w is the configuration q 0 w , which indicates that the machine is in the initial state q 0 , with its head in the leftmost position on the tape. In the accepting configuration , the state of this configuration is q accept . In the rejecting configuration, the state of the configuration is q reject . The accepting and rejecting configurations are final configurations and do not lead to further configurations. Since the machine is by definition supposed to halt when it enters the states q accept and q reject , we can equivalently define the transition function in the more complicated form δ : Q' × Γ Q × Γ × { L , R }, where Q' is the set of Q without the states q accept and q reject . A Turing machine M accepts an input w if there is a sequence of configurations C 1 , C 2 , … , C k such that

  1. C 1是M 的初始配置对于输入字w
  2. C 1 is the initial configuration of M For input word w ,
  3. 每个C i都会导致C i +1
  4. Every C i leads to C i +1 ,
  5. C k是接受配置。
  6. C k is the accepting configuration.

M接受的单词集合要么是机器 M 的语言,要么是 M 识别的语言,写为L ( M )。

The set of words accepted by M is the language of the machine M or the language recognized by M , written as L ( M ).

定义3.5

Definition 3.5

如果一种语言能够被某个图灵机1识别,则该语言被称为图灵可识别的

A language is called Turing recognizable if it is recognized by a Turing machine 1 .

当我们对输入词运行图灵机时,会出现三种可能的结果。机器可以接受、拒绝或循环。循环意味着机器不会停止。循环可能意味着任何简单或复杂的行为,永远不会导致终止状态。

When we run a Turing machine for an input word, there are three possible outcomes. The machine can accept, reject, or loop. By looping, we mean that the machine simply will not stop. Looping can mean any simple or complex behavior that never leads to a terminating state.

图灵机M可能无法通过进入q拒绝状态并彻底拒绝它或通过循环来接受输入。有时很难区分陷入循环的机器和只需要大量时间的机器。出于这些原因,我们更喜欢对每个输入终止的图灵机;这样的机器永远不会循环。这些机器被称为决定性的,因为它们总是决定是否接受或拒绝输入。如果解析机识别某种语言,我们就说它解析了它。

A Turing machine M can fail to accept an input either by entering state q reject and rejecting it outright, or by looping. It is sometimes difficult to distinguish a machine that has looped from one that simply takes a very long time. For these reasons, we prefer Turing machines that terminate for every input; such machines never loop. These machines are called deciders because they always decide whether to accept or reject the input. If a decider recognizes a language, we say that it decides on that language .

定义 3.6

Definition 3.6

一种语言在图灵意义上被称为可判定的,或者如果它可由某个图灵机2可判定,则称为可判定的

A language is called Turing- decidable , or simply decidable , if it is decidable by some Turing machine 2 .

我们现在将展示可判定语言的示例。请注意,每种可判定语言都是图灵可识别的。当我们开发证明不可判定性的技术时,我们将在第 4 章中展示图灵可识别但不可判定的语言示例。

We now give examples of decidable languages. Note that every decidable language is Turing recognizable. We will present examples of languages ​​that are Turing recognizable but not decidable in Chapter 4, when we develop techniques for proving undecidability.

图灵机的例子

Examples of Turing machines

与有限机器和堆栈机器一样,我们可以通过指定其七个部分中的每一个来正式描述特定的图灵机。然而,对于除了最简单的图灵机之外的所有图灵机来说,深入到这种细节级别可能会非常乏味。因此,我们不会花太多时间来呈现这样的描述。我们将主要提供更高级别的描述,因为它们足够精确以满足我们的需求并且更容易理解。然而,必须记住,任何更高级别的描述实际上只是其形式等效的缩写。只要有耐心和细心,我们就可以完整、正式地详细描述本书中介绍的每台图灵机。

As with finite-state machines and pushdown machines, we can formally describe a given Turing machine by specifying each of its seven parts. However, for all but the simplest Turing machines, going into such detail can be very tedious. For this reason, we will not spend much time on such descriptions. We will mainly give higher-level descriptions, since they are sufficiently precise for our purposes and much easier to understand. However, it is important to remember that each higher-level description is really just a shorthand for its formal counterpart. With some patience and care, we could describe every Turing machine presented in this book in full formal detail.

为了帮助您理解正式描述和更高级别描述之间的联系,我们在接下来的两个示例中提供了状态图。如果读者清楚地理解其中的联系,这些例子可以省略。

To help you understand the connections between formal descriptions and higher-level descriptions, we present state diagrams in the next two examples. These examples can be omitted if the reader already understands the connection.

3.7

Example 3.7

在这里,我们将描述一个图灵机(TM)M 2,它解析语言A = { 0 2 n : n ≥ 0},即由所有仅由零组成的单词组成的语言,其长度是 2 的幂。

Here we describe a Turing machine (TM) M 2 that resolves the language A = { 0 2 n : n ≥ 0}, that is, the language consisting of all words composed of zeros whose length is a power of 2.

M 2 =“对于输入字:

M 2 = "For input word in :

  1. 从左向右滚动磁带,每隔一个0划掉。
  2. Scan the tape from left to right, crossing out every other 0 .
  3. 如果第 1 阶段包含单个0,则接受
  4. If it contained a single 0 in phase 1 , accept .
  5. 如果磁带在第 1 阶段包含多个 0 并且 0 的数量为奇数,则丢弃
  6. If in phase 1 the tape contained more than a single 0 and the number of zeros was odd, discard .
  7. 将磁头移至磁带的左端。
  8. Move the head to the left end of the tape.
  9. 进入第一阶段。”
  10. Proceed to Phase 1."

第 1 阶段的每次迭代都会将零的数量减少一半。当机器在第一阶段梳理磁带时,它会记录它看到的零的数量是偶数还是奇数。如果这个数字是奇数并且大于 1,则输入字中的原始零个数不可能是 2 的幂。因此,在这种情况下,机器会拒绝该输入。但是,如果可见零的数量为 1,则原始数字必须是 2 的幂。所以在这种情况下机器接受。

Each iteration of phase 1 halves the number of zeros. As the machine scans the tape in phase 1, it keeps track of whether the number of zeros seen is odd or even. If that number is odd and greater than 1, the original number of zeros in the input word could not have been a power of 2. So in that case the machine rejects the input. However, if the number of zeros seen is 1, the original number must be a power of 2. So in that case the machine accepts.

我们现在给出M 2 = ( Q , Σ , Γ , δ, q 0 , q Accept , q Reserve )的正式描述:

We now give a formal description of M 2 = ( Q , Σ , Γ , δ, q 0 , q accept , q reject ):

  • Q = { q 1 , q 2 , q 3 , q 4 , q 5 , q接受, q拒绝},
  • Q = { q 1 , q 2 , q 3 , q 4 , q 5 , q accept , q reject },
  • Σ = {0},并且
  • Σ = {0}, and
  • γ = { 0 , x , }。
  • Γ = { 0 , x , }.
  • 我们将通过状态图来描述传递函数δ(图3.8)。
  • We will describe the transition function δ by a state diagram (Figure 3.8).
  • 初始状态、接受状态和拒绝状态分别是q 1q Acceptq Reject
  • The initial, accepting, and rejecting states are q 1 , q accept , and q reject , respectively .

3.8

图灵机M 2的状态图

Figure 3.8

State diagram for a Turing machine M 2

在此图中,标签 0 →  , R出现 在从状态q 1q 2的转换处。这个标签意味着当机器处于状态q 1并且磁头读取 0 时,机器进入状态q 2,写入并将磁头向右移动。换句话说,δ( q 1 , 0) = ( q 2 , , R )。为了清楚起见,在从状态q 3q 4的转换中,我们使用标签 0 R,这意味着机器在状态q 3读取 0 后向右移动,但不修改磁带的内容,即 δ ( q 3 , 0 ) = ( q 4 , 0 , R )。

In this diagram, the transition from state q 1 to q 2 is labeled 0  →  , R . This label means that when the machine is in state q 1 and the head reads 0, the machine moves to state q 2 , writes , and moves the head right. In other words, δ( q 1 , 0) = ( q 2 , , R ). In the transition from state q 3 to q 4 , for clarity, we use the label 0 R , by which we mean that the machine moves right after reading 0 in state q 3 , but does not modify the contents of the tape, that is, δ( q 3 , 0) = ( q 4 , 0, R ).

机器首先在磁带上最左边的 0 处写入一个空白符号,以便它可以在第 4 阶段找到磁带的左端。虽然我们通常会使用更具暗示性的符号,例如#作为结束分隔符,我们在这里使用空白符号来保持磁带字母表和状态图的小尺寸。例 3.11 显示了另一种查找磁带左端的方法。

The machine begins by writing a blank symbol to the leftmost 0 on the tape, so that it can find the left end of the tape in phase 4. Whereas we would normally use a more suggestive symbol such as # for the end delimiter , we use a blank symbol here to keep the tape alphabet, and hence the state diagram, small. Example 3-11 shows another method for finding the left end of the tape.

然后,我们将展示该机器对输入字0000的计算示例。初始配置为q 1 0000。机器进入的配置顺序如下所示;应该从左到右分栏阅读。

Next, we show an example computation of this machine for the input word 0000 . The initial configuration is q 1 0000 . The sequence of configurations that the machine enters is shown below; it is to be read by columns and from left to right.

3.9

Example 3.9

下面我们给出M 1 = ( Q , Σ , Γ , δ, q 0 , q Accept , q Reject )的正式描述,第 167 页非正式描述的图灵机解决了语言B = { w # w : w { 0,1}*}。

Below we give a formal description of M 1 = ( Q , Σ , Γ , δ, q 0 , q accept , q reject ), the Turing machine informally described on page 167 that resolves the language B = { w # w : w {0,1}*}.

  • Q = { q 1 , … , q 8 , q接受, q拒绝},
  • Q = { q 1 , … , q 8 , q accept , q reject },
  • Σ = {0, 1, #} 且Γ = {0, 1, #, x , }。
  • Σ = {0, 1, #} and Γ = {0, 1, #, x , }.
  • δ 函数以状态图的形式呈现(见下图)。
  • The δ function is represented in a state diagram (see the figure below).
  • 初始状态、接受状态和拒绝状态分别为q 1q Acceptq Reject
  • The initial, accepting, and rejecting states are q 1 , q accept , and q reject , respectively .

图 3.10 显示了图灵机M 1 的状态图,我们可以在从状态q 3到自身的转换上找到标签 0.1 R。该标签表示机器保持在q 3状态,在该状态下读取0 或1 时磁头向右移动,不会改变磁带上的符号。阶段1由状态q 1q 7实现,阶段2由其余状态实现。为了简化图,我们没有显示拒绝状态或导致拒绝状态的转换。当状态没有特定符号的传出转换时,默认情况下会发生这些转换。由于在状态q 5中没有箭头从#符号中出来,因此如果在该状态下头部击中#,则机器进入状态q拒绝。我们假设在每次导致拒绝状态的转变中,头部都会向右移动。

In Figure 3.10, a state diagram of a Turing machine M 1 , we can find the label 0,1 R on the transition from state q 3 to itself. This label means that the machine remains in state q 3 and moves the head to the right when it reads a 0 or 1 in that state. It does not change the symbol on the tape. Phase 1 is implemented by states q 1 to q 7 , and phase 2 by the remaining states. To simplify the diagram, we have not shown the reject state or the transitions that lead to it. These transitions occur by default whenever the state has no outgoing transition for a given symbol. Since there is no outgoing arrow with the symbol # in state q 5 , if the head encounters a # in that state, the machine moves to state q reject . We assume that the head moves to the right in each of the transitions leading to the reject state.

3.10

图灵机M 1的状态图

Figure 3.10

State diagram of the Turing machine M 1

3.11

Example 3.11

此处所示的M 3图灵机执行基本算术运算。它解析语言C = { a i b j c k : i × j = ki , j , k ≥ 1}。

The Turing machine M 3 shown here performs elementary arithmetic. It solves the language C = { a i b j c k : i × j = k and i , j , k ≥ 1}.

M 3 =“对于输入字:

M 3 = "For input word in :

  1. 从左到右扫描输入单词,检查它是否是a + b + c +的元素,如果不是则丢弃。
  2. Scan the input word from left to right to check if it is an element of a + b + c + , and reject if it is not.
  3. 将磁头移至磁带的左端。
  4. Move the head to the left end of the tape.
  5. 划掉a并将播放头向右移动到第一次出现b的位置。交替使用bc符号,划掉每种类型中的一个,直到没有b为止。如果所有c都已被划掉,而任何b仍保留,则丢弃
  6. Cross out a and move the head right to the first occurrence of b . Alternate between b and c , crossing out one of each, until there are no b s left . If all the c s have been crossed out and any b s remain , discard .
  7. 恢复划掉的b符号,如果还有 a需要划掉,则重复步骤 3。如果所有a都已被划掉,请检查所有c是否也已被划掉。如果是这样,请接受;否则丢弃。”
  8. Restore the crossed out b 's and repeat step 3 if there are any more a's to be crossed out. If all a's have been crossed out, check if all c's have also been crossed out. If so, accept ; otherwise reject ."

让我们仔细看看M 3机器的工作原理。在步骤 1 中,机器作为有限状态机运行。当头部从左向右移动时,不需要输入任何条目,使用其状态来检查输入单词的形式是否正确。

Let's look more closely at the operation of the machine M 3 . At step 1, the machine operates as a finite-state machine. No writes are needed as the head traverses from left to right, using its states to check that the input word is in the correct form.

第 2 步看起来很简单,但有一些微妙之处。机器如何找到输入磁带的左端?找到输入单词的右端很容易,因为输入以空白符号结尾。然而,左端最初没有标记。解决这个问题的一种方法是在计算的第一步中向最左边的输入符号添加一个标记。然后,当机器需要将磁头移动到磁带的左端时,它可以将磁头向左移动,直到碰到该标记。例 3.7 说明了该技术;磁带的左端标有空符号。

Step 2 looks just as simple, but it has a subtle twist. How can the machine find the left end of the input tape? Finding the right end of the input word is easy, since the input ends with a blank symbol. However, the left end initially has no tag. One way to solve this problem is to add a tag to the leftmost symbol of the input in the first step of the computation. Then, when the machine needs to move the head to the left end of the tape, it can move the head left until it hits that tag. Example 3.7 illustrates this technique; the left end of the tape is marked with a blank symbol.

找到磁带左端的一种稍微聪明的方法是使用我们定义的图灵机模型。回想一下,如果机器尝试将磁头移动到磁带左端之外,它将保持在同一位置。我们可以利用这个属性来构建一个左端检测器。为了检测磁头是否位于磁带的左端,机器可以在当前位置存储一个特殊符号,同时还记住该状态下被替换的符号。然后它尝试将头部移至左侧。如果仍然显示特殊符号,则表示左移失败,因此磁头必须位于磁带的左端。相反,如果它位于另一个符号上方,则一些符号会留在磁带上该位置的左侧。在继续操作之前,机器必须恢复已更改的符号,并将其替换为原始符号。

A slightly more clever way of finding the left end of the tape exploits how we defined the Turing machine model. Recall that if the machine tries to move the head past the left end of the tape, it will remain in the same place. We can use this property to build a left-end detector. To detect whether the head is at the left end of the tape, the machine can write a special symbol to the current position, while also remembering the symbol it is replacing in the state. It then tries to move the head to the left. If it is still pointing to the special symbol, then the left move was unsuccessful, and therefore the head must be at the left end of the tape. If it is instead over a different symbol, then some symbols remain to the left of that position on the tape. Before moving on, the machine must restore the changed symbol, replacing it with the original one.

第 3 阶段和第 4 阶段的实现很简单,并且每个阶段都使用几个状态。

The implementations of phases 3 and 4 are simple and each uses several states.

3.12

Example 3.12

这里展示的M 4图灵机解决了所谓的元素可区分性问题。它接收字母表 {0,1} 中由# 个字符分隔的单词列表作为输入,并且如果所有这些单词都不同,则预计会接受此输入。语言是

The Turing machine M 4 shown here solves the so-called element-distinguishability problem . It is given as input a list of words over the alphabet {0,1} separated by # characters and is required to accept this input if all the words are different. The language is

E = { # x 1 # x 2 ## x l:每个x i {0,1}* 且x i x j对于每个i j }。

E = { # x 1 # x 2 ## x l : every x i {0,1}* and x i x j for every i j }.

M 4机器的工作原理是比较x 1x 2x l中的单词,然后将x 2与x 3x l中的单词进行比较,依此类推。下面显示了解析该语言的M 4图灵机的非正式描述。

The machine M 4 operates by comparing x 1 with the words x 2 through x l , then comparing x 2 with the words x 3 through x l , and so on. An informal description of the Turing machine M 4 that resolves this language is shown below.

M 4 =“对于输入字:

M 4 = "For input word in :

  1. 在胶带最左边的符号上方放置一个标记。如果该符号为空符号,则接受。如果该符号为#,则转至下一步。否则,丢弃
  2. Place a check mark over the leftmost symbol on the tape. If that symbol was a blank symbol, accept . If that symbol was # , go to the next step. Otherwise, reject .
  3. 浏览入口右侧的下一个#号并在其上放置第二个标记。如果空符号之前没有# ,则输入单词仅包含x 1,因此接受
  4. Traverse the input right to the next # character and place a second tag on it. If no # character occurs before the blank, the input word contains only x 1 so accept .
  5. Zigzag,比较标记#右侧的两个单词。如果这些词相等,则拒绝
  6. Zigzagging, compare the two words to the right of the ones marked # . If the words are equal, discard .
  7. 将右侧标记移动到右侧下一个#符号。如果空白符号之前没有出现#符号,则将左侧标记移动到其右侧的下一个#,将右侧标记移动到其后面的下一个#。如果右侧标签没有后续#,则表示所有单词都已比较,因此接受
  8. Move the right tag to the next # to the right. If there is no # before the empty tag, move the left tag to the next # to its right, and the right tag to the next # after it. If there is no next # for the right tag, it means that all words have been compared, so accept .
  9. 转到步骤 3。”
  10. Go to step 3."

这台机器演示了在磁带上标记符号的技术。在步骤 2 中,机器在符号上方放置一个标记,在本例中为#。在实际实施中,机器在其磁带字母表中将有两个不同的符号## 。说机器在#上方放置复选标记意味着机器在该字段中写入符号# 。去掉标签意味着机器写入的符号不带点。一般来说,您需要在磁带上的各种符号上放置标记。为此,我们只需将所有符号的点版本附加到磁带字母表上。

This machine illustrates a technique for marking symbols on tape. In step 2, the machine places a mark over a symbol, in this case # . In an actual implementation, the machine will have two different symbols # and # in its tape alphabet. Saying that the machine places a mark over # means that the machine writes the symbol # in that field. Removing the mark means that the machine writes the symbol without the dot. In general, we will want to place marks over different symbols on the tape. To do this, we will simply append the dotted versions of all the symbols to the tape alphabet.

从所提供的示例中,我们可以得出结论,其中描述的语言ABCE是可判定的。所有可判定的语言也是图灵可识别的,因此这些语言也是图灵可识别的。展示一种图灵可识别但不可判定的语言更加困难。我们将在第 4 章中完成此操作。

From the examples given, we can conclude that the languages ​​A , B , C , and E described in them are decidable. All decidable languages ​​are also Turing recognizable, so these languages ​​are also Turing recognizable. Demonstrating a language that is Turing recognizable but not decidable is more difficult. We will do this in Chapter 4.

3.2

图灵机的种类

3.2

Varieties of Turing machines

图灵机有很多定义,包括多带或非确定性版本。我们称它们为图灵机模型的变体。原始模型及其合理的变体具有相同的处理能力——它们都识别同一类语言。在本节中,我们将描述其中一些变体及其计算能力等价证明。这种对定义中特定变化的不敏感称为免疫。有限状态机和堆栈机在某种程度上都是弹性模型,但图灵机的弹性是惊人的。

There are many definitions of Turing machines, including versions with multiple tapes or nondeterminism. We call these variants of the Turing machine model. The original model and its reasonable variants have the same computational power—they all recognize the same class of languages. In this section, we describe some of these variants and proofs of their computational power equivalence. This insensitivity to specific changes in the definition is called robustness . Both finite-state machines and pushdown automata are robust models to some extent, but the robustness of the Turing machine is astonishing.

为了说明图灵机模型的鲁棒性,让我们尝试改变允许的传递函数的类型。在我们的定义中,转换函数迫使头部在每一步之后向左或向右移动;头部不能只是停留在原地。假设我们允许图灵机具有保持原地的能力。传递函数的形式为 δ : Q × Г Q × Г × { L , R , S} 。此功能是否允许图灵机识别其他语言,从而增强模型的功能?当然不是,因为我们可以将任何具有固定功能的图灵机转换为不具有该功能的图灵机。为此,我们将每个停留传球替换为两次传球:一次将头部移动到右侧,另一次将头部移动到左侧。

To illustrate the robustness of the Turing machine model, let us try to vary the types of transition functions that are allowed. In our definition, the transition function forces the head to move left or right after each step; the head cannot simply stay in place. Suppose we allow the Turing machine to have the ability to stay in place. The transition function then becomes δ : Q × Γ Q × Γ × { L , R , S}. Will this functionality allow Turing machines to recognize additional languages, thereby increasing the power of the model? Of course not, since we can convert any Turing machine with a “stay in place” function into one that does not. We do this by replacing each stay-in-place transition with two stay-in-place transitions: one that moves the head to the right and one that moves it to the left.

这个小例子提供了证明图灵机变体等价性的关键。为了证明两个模型是等价的,我们只需要证明其中一个模型可以模拟另一个模型的行为。

This little example contains the key to proving the equivalence of Turing machine variants. To prove that two models are equivalent, we need only show that one can simulate the action of the other.

多带图灵机

Multi-tape Turing machines

多磁带图灵机与正则图灵机类似,但具有多个磁带。每个磁带都有自己的读/写头。最初,输入数据位于第一个磁带上,其余磁带为空白。转换功能被更改为允许同时在选定的或所有磁带上读取、写入和移动磁头。形式上,它有一个形式

A multitape Turing machine is similar to an ordinary Turing machine, but has multiple tapes. Each tape has its own read/write head. Initially, the input data is on the first tape, and the remaining tapes are empty. The transition function is modified to allow reading, writing, and moving heads on some or all tapes simultaneously. Formally, it has the form

δ : Q × Γ k Q × Γ k × { L , R , S } k ,

δ : Q × Γ k Q × Γ k × { L , R , S } k ,

其中k是磁带数量。表达

where k is the number of tapes. The expression

δ( q i , a 1 , …, a k ) = ( q j , b 1 , …, b k , L , R , …, L )

δ( q i , a 1 , …, a k ) = ( q j , b 1 , …, b k , L , R , …, L )

表示如果机器处于状态q i,头 1 到k读取符号a 1a k,则机器进入状态q j,写入符号b 1b k,并向左或向右移动每个头或离开它仍然。

means that if the machine is in state q i , and heads 1 through k are reading symbols a 1 through a k , the machine goes to state q j , writes symbols b 1 through b k , and moves each head left or right or leaves it stationary.

多带图灵机可能看起来比普通图灵机更强大,但我们可以证明它们的计算能力是相当的。回想一下,如果两台机器识别相同的语言,那么它们是等效的。

Multi-tape Turing machines may seem more powerful than regular ones, but we can show that their computational power is equivalent. Recall that two machines are equivalent if they recognize the same language.

定理3.13

Theorem 3.13

对于每个多磁带图灵机,都有一个等效的单磁带图灵机。

For every multi-tape Turing machine there is an equivalent single-tape Turing machine.

证明 我们将展示如何将多带图灵机M转换为等效的单带图灵机S。关键思想是展示如何使用S模拟M。

Proof We show how to transform a multi-tape Turing machine M into an equivalent single-tape Turing machine S . The key idea is to show how to simulate M using S .

假设Mk 个磁带。然后,S通过将k 个磁带的内容存储在其单个磁带上来模拟 k 个磁带的操作。机器S使用新的#符号作为分隔符来分隔不同磁带的内容。除了这些磁带的内容之外,S还必须跟踪各个磁头的位置。它通过在磁带上写一个符号并在其上方加一个点来指示该磁带的磁头位置来实现此目的。我们可以将它们视为“虚拟”磁带和磁头。和以前一样,“点”磁带符号只是我们添加到磁带字母表中的新符号。下图显示了如何用一盘磁带代表三盘磁带。

Suppose M has k tapes. Then S simulates the operation of k tapes by storing their contents on its single tape. Machine S uses the new symbol # as a delimiter to separate the contents of the different tapes. In addition to the contents of these tapes, S must keep track of the position of the individual heads. It does this by writing a symbol on the tape with a dot above it to mark where the head of that tape should be. We can think of these as "virtual" tapes and heads. As before, the "dotted" tape symbols are simply new symbols that we have added to the tape alphabet. The following figure shows how one tape can be used to represent three tapes.

3.14

用一个磁带代表三个磁带

Figure 3.14

Representing three tapes using one

S =“对于输入字w = w 1 ... w n

S = "For input word w = w 1w n :

  1. 首先,S将其磁带设置为代表机器M的所有k 个磁带的格式。格式化的磁带包含

    8

  2. First, S formats its tape to represent all k tapes of machine M . The formatted tape contains



  3. 为了模拟单次移动,S从第一个#字符(表示左端)到第 ( k + 1) 个#字符(表示右端)扫描磁带,以确定位于虚拟头下方的符号。然后,S按照机器M的转换函数的指示执行第二遍以更新磁带。
  4. To simulate a single move, S scans its tape from the first # character , which designates the left end, to the ( k + 1)th # character, which designates the right end, to determine the symbols that are under the virtual heads. S then performs a second pass to update the tapes as directed by the transition function of machine M .
  5. 如果任何时候S将其中一个虚拟磁头移动到#标记处的右侧,则此操作意味着M已将相应的磁头移动到磁带上先前未读取的空部分。因此,S向该磁带单元写入一个空白符号,并将磁带内容从该单元移动到最右边的#字符,向右移动一位。然后它会像以前一样继续进行模拟。”

  6. If at any time S moves one of the virtual heads to the right to the # character , this action means that M has moved the corresponding head to a previously unread, empty part of the tape. Therefore, S writes an empty symbol to that tape cell and shifts the tape contents from that cell to the rightmost # character one position to the right. It then continues the simulation as before."

应用3.15

Motion 3.15

一种语言是图灵可识别的,当且仅当它被某些多频带图灵机识别时。

A language is Turing-recognizable if and only if it is recognized by some multi-tape Turing machine.

证明 图灵可识别的语言可以被普通(单带)图灵机识别,这是多带图灵机的特例。这证明了这个结论的一个方向。定理 3.13 得出相反的方向。

Proof A Turing-recognizable language is recognized by an ordinary (single-tape) Turing machine, which is a special case of a multi-tape Turing machine. This proves one direction of this corollary. The opposite direction follows from Theorem 3.13.

非确定性图灵机

Nondeterministic Turing machines

非确定性图灵机的定义正如预期的那样。在计算的任何给定点,机器都可以通过多种方式继续。非确定性图灵机的转换函数具有以下形式

The definition of a nondeterministic Turing machine is as expected. At any point in the computation, the machine can continue in several ways. The transition function for a nondeterministic Turing machine is of the form

δ : Q × Г P ( Q × Г × { L , R })。

δ : Q × Γ P ( Q × Γ × { L , R }).

非确定性图灵机的计算流程是一棵树,其分支对应于机器的各种能力。如果某个计算路径导致接受状态,则机器接受其输入。如果读者想刷新非确定性的概念,他应该返回到 1.2 小节(第 47 页)。我们现在将证明不确定性不会影响图灵机模型的计算能力。

The computational path of a nondeterministic Turing machine is a tree whose branches correspond to the different capabilities of the machine. If some computational path leads to an accepting state, the machine accepts its input. If the reader wants to refresh his memory on the concept of nondeterminism, he should refer back to Section 1.2 (page 47). We now show that nondeterminism does not affect the computational power of the Turing machine model.

定理3.16

Theorem 3.16

对于每个非确定性图灵机,都有一个等效的确定性图灵机。

For every nondeterministic Turing machine there is an equivalent deterministic Turing machine.

证明的概念我们可以通过确定性图灵机D 来模拟任何非确定性图灵机N。该模拟背后的想法是D尝试N执行的非确定性计算的所有可能分支如果D在这些分支之一上找到接受状态,它就会接受输入。否则,模拟D永远不会结束。

Proof Concept We can simulate any nondeterministic Turing machine N by a deterministic Turing machine D . The idea behind this simulation is that D tries all possible branches of the nondeterministic computation performed by N . If D ever finds an accepting state on one of these branches, then it accepts the input. Otherwise, the simulation of D never terminates.

我们将输入词w上的N计算视为一棵树。树的每个分支代表非决定论的一个分支。树的每个顶点都是机器N的配置。树的根是初始配置。机器D在此树中搜索接受配置。仔细执行此搜索对于确保D不会错过树的任何部分至关重要。一个诱人但糟糕的想法是通过深度优先搜索来遍历D树。深度优先搜索策略涉及完成一个分支到最后,然后返回探索后续分支。如果机器D以这种方式解析树,它可能会遇到某个无限分支,并在该分支上永远徘徊,并且在其他计算路径上找不到接受配置。因此,我们将设计D使用广度优先搜索来遍历树。该策略涉及在继续检查下一个级别的任何分支之前检查相同深度的所有分支。该方法保证如果接受配置存在于树中,D将在有限时间内找到它。

We will view the computation of N on input w as a tree. Each branch of the tree represents one of the branches of nondeterminism. Each node of the tree is a configuration of machine N . The root of the tree is the initial configuration. Machine D searches this tree for an accepting configuration. Careful execution of this search is critical so that D does not miss any part of the tree. It is tempting, but a bad idea, to traverse the tree through D by depth-first search. The strategy of depth-first search is to traverse one branch to the end before returning to examine the next branches. If machine D were to traverse the tree in this way, it might encounter some infinite branch, which it would forever traverse downward, and fail to find an accepting configuration on some other computational path. Therefore, we will design D to traverse the tree by breadth-first search. This strategy involves examining all branches to the same depth before proceeding to examine any branches at the next level. This method guarantees that if an accepting configuration exists in the tree, D will find it in finite time.

证明模拟确定性图灵机D包含三个磁带。根据定理 3.13,这相当于使用一盘磁带。机器D以特定方式使用其三个磁带,如下图所示。磁带 1 始终包含输入字并且永远不会被修改。磁带 2在其非确定性计算的某些路径上保留机器N的磁带副本。磁带 3 存储有关机器D在机器N的非确定性计算树中的位置的信息。

Proof A simulating deterministic Turing machine D contains three tapes. By Theorem 3.13, this is equivalent to using one tape. Machine D uses its three tapes in a special way, as illustrated in the following figure. Tape 1 always contains an input word and is never modified. Tape 2 keeps a copy of the tape of machine N on some path of its nondeterministic computations. Tape 3 stores information about D' s location in the nondeterministic computation tree of machine N .

3.17

确定性图灵机D模拟非确定性图灵机N

Figure 3.17

A deterministic Turing machine D simulating a nondeterministic Turing machine N

首先,考虑磁带 3 上的数据表示。树中的每个节点最多可以有b个子节点,其中b是由机器的转换函数N产生的最大可能选择集的大小。我们为树的每个顶点分配一个地址,该地址是字母表上方的一个单词Γ b = {1, 2, . 。 。 ,b }。我们将地址 231 分配给我们到达的顶点,从根开始,转到它的第二个子节点,然后从那里到第三个子节点,最后从该顶点到它的第一个子节点。每个单词符号告诉我们在模拟非确定性机器计算N的一条路径中的步骤时必须做出什么选择。有时,如果给定配置中的选项太少,则某个符号可能不对应于任何选择。在这种情况下,该地址无效,不对应任何节点。磁带 3 包含字母表Γ b上方的单词。它表示从根到该字所寻址的节点的计算路径N,除非该地址无效。空字是树根的地址。现在我们可以描述机器D了。

First, consider the representation of the data on tape 3. Each vertex of the tree can have at most b children, where b is the size of the largest set of possible choices resulting from the transition function of machine N . We assign each vertex of the tree an address that is a word over the alphabet Γ b = {1, 2, . . . , b }. We assign address 231 to the vertex we reach by starting at the root, going to its second child, then from there going to the third child, and finally from that vertex to its first child. Each symbol in the word tells us what choice to make when simulating a step in one path of nondeterministic computation of machine N . Sometimes a symbol may not correspond to any choice if there are too few possibilities in the given configuration. In such a case, the address is invalid and does not correspond to any node. Tape 3 contains a word over the alphabet Γ b . It represents the path of computation of N from the root to the node addressed by that word, unless the address is invalid. The empty word is the address of the root of the tree. Now we can describe the machine D .

  1. 最初,磁带 1 包含输入词w,磁带 2 和 3 为空。
  2. Initially, tape 1 contains the input word w , and tapes 2 and 3 are empty.
  3. 我们将磁带 1 的内容复制到磁带 2。
  4. We copy the contents of tape 1 to tape 2.
  5. 我们使用磁带 2 来模拟机器N在其非确定性计算路径之一上对输入字w的操作。在机器N 的每个步骤之前,我们检查磁带 3 上的下一个符号,以确定在转换函数N允许的符号中做出什么选择。如果磁带 3 上没有更多的符号或者这种非确定性选择是不可能的,我们放弃这条路径,转到步骤 4。当我们遇到丢弃配置时,我们也会转到步骤 4。如果出现接受配置,我们就接受输入单词。
  6. We use tape 2 to simulate the operation of machine N on input word w on one of its nondeterministic computation paths. Before each step of machine N , we examine the next symbol on tape 3 to determine what choice to make among those allowed by the transition function of N . If there are no more symbols on tape 3 or this nondeterministic choice is impossible, we abandon this path and go to step 4. We also go to step 4 if we encounter a rejecting configuration. If an accepting configuration appears, we accept the input word.
  7. 我们用字典顺序中的下一个单词替换磁带 3 上的单词。我们模拟N 的下一个计算路径,进入阶段 2。
  8. We replace the word on tape 3 with the next word in lexicographic order. We simulate the next path of computation N , moving on to phase 2.

应用 3.18

Motion 3.18

当且仅当某些非确定性图灵机能够识别一种语言时,它才是图灵可识别的。

A language is Turing-recognizable if and only if it is recognized by some nondeterministic Turing machine.

证明 每个确定性图灵机自动都是一个非确定性机器,因此我们立即获得一个蕴涵方向的真相。相反方向的正确性由定理 3.16 得出。

Proof Every deterministic Turing machine is automatically a nondeterministic Turing machine, so we immediately obtain that one direction of the implication is true. The opposite direction is true by Theorem 3.16.

我们可以修改定理 3.16 的证明,这样如果N在每个计算路径上都停止,那么 D 也总是停止。如果非确定性图灵机在所有输入的所有计算路径上停止,则该图灵机被称为决定性图灵机。练习 3.3 要求我们修改证明以获得定理 3.16 中的以下结论。

We can modify the proof of Theorem 3.16 so that if N halts on every computational path, then D always halts as well. A nondeterministic Turing machine is called decisive if it halts on all computational paths for all inputs. Exercise 3.3 instructs us to modify the proof so as to obtain the following corollary of Theorem 3.16.

应用 3.19

Motion 3.19

一种语言是可判定的,当且仅当它可以由某个非确定性图灵机确定时。

A language is decidable if and only if it is decidable by some nondeterministic Turing machine.

枚举器

Enumerators

正如我们前面提到的,图灵可识别的语言有时被称为递归可枚举语言。该术语来自图灵机的一种变体,称为枚举器(即枚举机)。直观上,枚举器是一台附有打印机的图灵机。图灵机可以使用打印机作为输出设备来输出单词列表。每当图灵机想要向该列表添加一个单词时,它就会将其发送到打印机。在练习 3.4 中,提供了枚举数的正式定义。该模型的示意图如下图所示。

As mentioned earlier, Turing-recognizable languages ​​are sometimes called recursively enumerable languages ​​. This term is derived from a variant of the Turing machine called an enumerator . Intuitively, an enumerator is a Turing machine with a printer attached . A Turing machine can use the printer as an output device to print out a list of words. Whenever the Turing machine wants to add a word to this list, it sends it to the printer. In Exercise 3.4, you are asked to give a formal definition of an enumerator . The schematic of this model is shown in the figure below.

3.20

枚举器图

Figure 3.20

Enumerator diagram

枚举器E在其工作带上以空输入开始计算。如果枚举器不停止,它可以输出无限的单词列表。E枚举的语言是最终要打印的所有单词的集合。此外,E可以以任何顺序生成该语言的单词,也许可以重复。

The enumerator E starts the computation with an empty input on its work tape. If the enumerator does not stop, it can output an infinite list of words. The language computed by E is the set of all words that will eventually be printed. Moreover, E can output the words of the language in any order, possibly with repetitions.

我们现在可以转向枚举器和图灵可识别语言之间的关系。

We can now move on to the relationship between enumerators and Turing-correctable languages.

定理3.21

Theorem 3.21

一种语言是图灵可识别的当且仅当它被某个枚举器枚举时。

A language is Turing recognizable if and only if it is enumerated by some enumerator.

证明首先, 我们将证明,如果我们有一个枚举器E枚举语言A,那么某个图灵机M可以识别A。机器M的工作原理如下。

Proof We first show that if we have an enumerator E enumerating a language A , then some Turing machine M recognizes A . The machine M operates as follows.

M =“对于中的输入词:

M = "For input word in :

  1. 我们运行E。每次E返回一个单词时,我们都会将其与w进行比较。
  2. We run E . Each time E returns a word, we compare it with w .
  3. 如果w出现在E输出中,则接受“。
  4. If w ever appears in the E output , accept ".

很明显,M接受机器E列表中出现的那些单词。

It is obvious that M accepts those words that appear in the list of machine E .

现在我们将采取相反的方向。如果图灵机M识别语言A,我们可以为该语言构造以下枚举器。令s 1 , s 2 , s 3 , … 为属于Σ *的所有可能单词的列表。

Now we go in the opposite direction. If a Turing machine M recognizes a language A , then we can construct the following enumerator for that language. Let s 1 , s 2 , s 3 , … be a list of all possible words belonging to Σ * .

E =“忽略输入单词。

E = "Ignore input word.

  1. 对i = 1, 2, 3, …重复以下操作
  2. Repeat the following for i = 1, 2, 3, …
  3. 对于每个输入s 1 , s 2 , … , s i,在i 个步骤上运行M。
  4. Run M for i steps for each input s 1 , s 2 , … , s i .
  5. 如果任何计算导致接受某个单词 s j,则将其打印出来。”
  6. If any of the calculations results in the acceptance of some word s j , then print that word."

如果M接受特定单词s ,那么它将出现在E生成的列表中。事实上,它会在列表中出现无限次,因为每次重复步骤 1 时, M都会针对每个单词从头开始运行。此过程具有针对所有可能的输入单词并行运行M的效果。

If M accepts a particular word s , then it will appear in the list generated by E . In fact, it will appear in the list infinitely many times, since M is run from the beginning for each word for each repetition of step 1. This procedure has the effect of running M in parallel for all possible input words.

与其他型号的等效性

Equivalence with other models

到目前为止,我们已经提出了图灵机模型的几种变体,并表明它们在计算能力方面是等效的。许多其他通用计算模型已经被开发出来。其中一些模型与图灵机非常相似,但其他模型则显着不同。它们都具有图灵机的一个基本特征,即无限制地访问无限内存,这将它们与有限状态机和堆栈机等较弱的模型区分开来。然而,重要的是,如果满足合理的要求,所有具有此属性的模型在计算能力方面都是等效的3

So far, we have presented several variants of the Turing machine model and shown that they are equivalent in terms of computational power. Many other general-purpose models of computation have been developed. Some of these models are very similar to Turing machines, but others differ significantly. All share the basic feature of Turing machines—namely, unrestricted access to infinite memory—which distinguishes them from weaker models such as finite-state machines and pushdown machines. Importantly, however, all models with this property turn out to be equivalent in terms of computational power, provided they satisfy reasonable requirements 3 .

为了理解这种现象,让我们考虑一下编程语言环境中的类似情况。其中许多,例如 Pascal 和 Lisp,在编程风格和结构方面看起来完备不同。是否可以将某种算法编程到一个算法中而不是其他算法中?当然不是——我们可以将用 LISP 编写的程序重新编译为 Pascal,反之亦然,这意味着两种语言描述的算法完备相同。这适用于所有其他合理的编程语言。计算模型的普遍等价性源于完备相同的原因。任何满足一定合理要求的两个计算模型都可以相互模拟,因此计算能力相当。

To understand this phenomenon, consider an analogous situation in the context of programming languages. Many of them, such as Pascal and LISP, look quite different in terms of programming style and structure. Can a certain algorithm be programmed in one but not the other? Of course not—we can recompile a LISP program into Pascal and vice versa, which means that both languages ​​describe exactly the same class of algorithms. The same is true for all other sensible programming languages. The universal equivalence of computational models follows for exactly the same reason. Any two computational models that satisfy certain reasonable requirements can simulate each other and are therefore equivalent in terms of computational power.

这种等价现象引出了一个重要的哲学结论。尽管我们可以想象许多不同的计算模型,但它们描述的算法类别仍然是相同的。尽管每个特定计算模型的定义都包含一些任意假设,但它描述的算法类别是自然的,因为其他模型会导致相同的、明确定义的类别。正如我们将在下一节中展示的那样,这种现象对数学具有重大意义。

This equivalence phenomenon leads to an important philosophical conclusion. Although we can imagine many different models of computation, the class of algorithms they describe remains the same. Although the definition of any particular model of computation involves some arbitrary assumptions, the class of algorithms it describes is natural, since other models lead to the same, uniquely defined class. This phenomenon has important implications for mathematics, as we will show in the next section.

3.3

算法定义

3.3

Algorithm Definition

直观地说,算法是执行某项任务的一组简单指令。算法在日常生活中很常见,有时被称为过程菜谱。算法在数学中也发挥着重要作用。旧的数学文献包含对各种任务的算法的描述,例如查找素数和查找最大公约数。算法在现代数学中很常见。

Intuitively speaking, an algorithm is a set of simple instructions for performing a task. Algorithms are common in everyday life and are sometimes called procedures or recipes . Algorithms also play an important role in mathematics. Early mathematical literature contains descriptions of algorithms for various tasks, such as finding prime numbers or finding the greatest common divisor. In modern mathematics, algorithms are common.

尽管算法在数学领域有着悠久的历史,但算法本身的概念直到二十世纪才被精确定义。以前,数学家直观地理解算法是什么,并依靠这种理解来描述和使用它们。然而,这种直观的概念不足以加深对算法的理解。下面的故事表明,精确定义算法对于解决一个重要的数学问题至关重要。

Although algorithms have a long history in mathematics, the concept of an algorithm was not precisely defined until the twentieth century. Before that, mathematicians had an intuitive understanding of what algorithms were and relied on that understanding to describe and use them. However, this intuitive understanding was insufficient for gaining a deeper understanding of algorithms. The history that follows shows that precisely defining algorithms was critical to one of the most important problems in mathematics.

希尔伯特问题

Hilbert's Problems

1900 年,数学家大卫希尔伯特在巴黎国际数学大会上发表了他现在著名的演讲。在他的演讲中,他提出了 23 个构成下世纪挑战的数学问题。该列表中的第十个问题与算法有关。

In 1900, the mathematician David Hilbert gave a now-famous talk at the International Mathematical Congress in Paris. In his talk, he identified 23 mathematical problems that would challenge the coming century. The tenth problem on that list concerned algorithms.

在描述这个问题之前,让我们简单回顾一下多项式的概念。多项式是多项式的总和,其中每一项都是某些变量和称为系数的常数的乘积。例如

Before describing this problem, let's briefly recall the concept of polynomials. A polynomial is a sum of terms in which each term is the product of some variables and a constant called the coefficient . For example

x·x·x·y·z·z = 6 x 3 yz 2

6 · x · x · x · y · z · z = 6 x 3 yz 2

是因子为 6 的分量,并且

is a component with a coefficient of 6, and

6 x 3 yz 2 + 3 xy 2x 3 − 10

6 x 3 yz 2 + 3 xy 2x 3 − 10

是具有四个分量和变量xyz的多项式。出于我们考虑的目的,我们将仅考虑整数系数。多项式的是为其变量赋值,使得多项式的值为 0。该多项式的根为x = 5、y = 3 和z = 0。该解是整数根,因为所有变量都有整数值。有些多项式有整数根,有些则没有。

is a polynomial with four terms and variables x , y , and z . For the purposes of our discussion, we will consider only the coefficients that are integers. A root of a polynomial is an assignment of values ​​to its variables such that the value of the polynomial is 0. This polynomial has a root for x = 5, y = 3, and z = 0. This solution is an integer root , since all variables have integer values. Some polynomials have integer roots, while others do not.

希尔伯特的第十个问题是提出一种算法来检查给定多项式是否具有整数根。他没有使用术语“算法”,而是“可以通过有限数量的操作来确定这一点的适当过程” 4。有趣的是,在这个问题的表述方式中,希尔伯特明确表示这个算法是要“推导的”。因此,他无疑认为这样的算法一定存在——只是需要有人找到它。

Hilbert's tenth problem was to propose an algorithm for determining whether a given polynomial has an integer root. He did not use the term algorithm , but rather "a suitable process by which this may be established in a finite number of operations." 4 Interestingly, in the way he formulated the problem, Hilbert explicitly stated that the algorithm was to be "derived." By doing so, he undoubtedly assumed that such an algorithm must exist—someone just has to find it.

目前已知不存在用于此任务的算法;它在算法上是无法解决的。对于这个时期的数学家来说,用他们直观的算法概念得出这个结论几乎是不可能的。直观的概念可能足以显示特定任务的算法,但无法显示特定任务不存在算法。证明算法不存在需要对算法有明确的定义。第十个问题的进展必须等待这样的定义。

It is now known that no algorithm exists for this problem; it is algorithmically insoluble. For mathematicians of that period, reaching this conclusion with their intuitive conception of an algorithm was practically impossible. An intuitive conception may be sufficient for presenting algorithms for specific tasks, but it is useless for showing that for a certain task no algorithm exists. Showing that an algorithm does not exist requires having an unambiguous definition of an algorithm. Progress on the tenth problem had to await such a definition.

这个定义是在 1936 年 Alonzo Church 和 Alan Turing 的著作中提出的。 Church 使用称为 lambda 演算的符号系统来定义算法。图灵用他的“机器”做到了这一点。如图所示,这两个定义是等价的。算法的非正式概念与精确定义之间的这种联系称为丘奇-图灵假设

This definition was introduced in 1936 in the work of Alonzo Church and Alan Turing. Church used a notation called lambda calculus to define algorithms. Turing did this using his "machines". The two definitions have been shown to be equivalent. This link between the informal notion of an algorithm and the precise definition is called the Church–Turing hypothesis .

丘奇-图灵假设提供了解决希尔伯特第十个问题所需算法的定义。 1970 年,Yuri Matijasevič 在 Martin Davis、Hilary Putnam 和 Julia Robinson 的工作基础上证明了不存在用于测试多项式是否具有整数根的算法。在第四章中,我们开发了一些技术,为证明这个问题和其他问题在算法上是无法解决的提供了基础。

The Church–Turing thesis provides the definition of an algorithm necessary to solve Hilbert's tenth problem. In 1970, Yuri Matijasevič, building on the work of Martin Davis, Hilary Putnam, and Julia Robinson, proved that there is no algorithm for testing whether a polynomial has integer roots. In Chapter 4, we develop the techniques that underlie the proof that this and other problems are algorithmically insolvable.

3.22

丘奇-图灵假设

Figure 3.22

The Church-Turing hypothesis

让我们用我们的符号来表述希尔伯特的第十个问题。这将使我们更容易介绍我们将在第 4 章和第 5 章中探讨的一些主题。让

Let us formulate Hilbert's tenth problem using our notation. This will make it easier to introduce some of the topics we will learn in Chapters 4 and 5. Let

D = { p : p是整数多项式}。

D = { p : p is a polynomial with an integer root}.

希尔伯特第十个问题本质上是问集合D是否可判定。答案是否定的。但我们可以证明D是图灵可识别的语言。在这样做之前,我们首先考虑一个更简单的问题。它类似于只有一个变量的多项式的希尔伯特第十个问题,例如 4 x 3 − 2 x 2 + x − 7。让

Hilbert's tenth problem is really the question of whether D is decidable. The answer is negative. But we can show that D is a Turing-decidable language. Before we do that, let's first consider a simpler problem. It is analogous to Hilbert's tenth problem for polynomials that have only one variable, such as 4 x 3 − 2 x 2 + x − 7. Let

D 1 = { p : p是变量x的具有整数根的多项式}。

D 1 = { p : p is a polynomial in x with an integer root}.

这是识别语言D 1 的图灵机M 1

Here is a Turing machine M 1 recognizing the language D 1 :

M 1 = “对于输入词p :其中p是变量x的多项式。

M 1 = "For input word p : where p is a polynomial in the variable x .

  1. 我们通过用值 0, 1, −1, 2, −2, 3, −3, ... 代替x来计算p。如果在任何时候多项式的值为 0,我们就接受。
  2. We calculate p by substituting x with the values ​​0, 1, −1, 2, −2, 3, −3, … If at any point the value of the polynomial is 0, we accept".

如果p有一个整数根,M 1最终会找到它并终止。如果p没有整数根,则M 1将无限期地继续。对于多变量情况,我们可以提出一个类似的图灵机M识别D。在这种情况下,M将遍历多项式变量的所有可能的整数替换。

If p has an integer root, M 1 will eventually find it and terminate. If p has no integer root, then M 1 will run forever. For the multivariable case, we can imagine an analogous Turing machine M recognizing D . In this case, M will run through all possible integer substitutions for the polynomial variables.

M 1M识别该语言但不解析它。我们可以将M 1变换为D 1的结论,因为我们可以计算(估计)单变量多项式的根必须位于的极限,并将搜索限制在这些极限内。在问题 3.21 中,有必要证明这样的多项式的根必须位于值之间

M 1 and M recognize the language, but do not resolve it. We can transform M 1 so that it becomes resolvent for D 1 , since we can compute (estimate) the limits within which the roots of a polynomial in one variable must lie, and restrict the search to these limits. In Problem 3.21, we need to show that the roots of such a polynomial must lie between the values

其中k是多项式的项数,c max是绝对值最大的系数,c 1是变量的最高幂项的系数。如果在此区间内没有找到根,机器将拒绝该输入。 Matijasevic 定理表明不可能计算多元多项式的此类约束。

where k is the number of terms in the polynomial, c max is the coefficient of the largest absolute value, and c 1 is the coefficient of the term with the highest power of the variable. If the root is not found in this interval, the machine rejects the input. Matijasevic's theorem shows that computing such bounds for polynomials in several variables is impossible.

描述图灵机的约定

Convention for describing Turing machines

我们已经到达了理解计算理论的转折点。我们仍然会谈论图灵机,但从现在开始我们真正感兴趣的领域将是算法。换句话说,图灵机只会作为一个精确的模型来定义算法。我们将忽略图灵机本身的理论,并且不会花太多时间对其进行低级编程。我们只需要足够自由地引用图灵机,就可以相信它们涵盖了所有算法。

We have reached a turning point in the study of the theory of computation. We will continue to speak of Turing machines, but our real area of ​​interest from now on will be algorithms. In other words, Turing machines will serve only as a precise model for defining an algorithm. We will ignore the theory of Turing machines themselves and will not spend much time on low-level programming of them. We need only to refer loosely enough to Turing machines to believe that they encompass all algorithms.

考虑到这一点,我们现在将标准化描述图灵机算法的方式。首先,我们需要问一个问题:在描述此类算法时,适当的详细程度是多少?学生经常问这个问题,尤其是在做练习和问题时。让我们考虑三种可能性。第一个是形式化描述,列举了图灵机的所有状态、转移函数等等。这是最低、最详细的描述级别。

With this in mind, we now standardize the way in which we describe Turing machine algorithms. First, we must ask the question: What is the appropriate level of detail for describing such algorithms? Students often ask this question, especially when solving exercises and problems. Let's consider three possibilities. The first is a formal description, enumerating all the states of the Turing machine, the transition function, and so on. This is the lowest, most detailed level of description.

第二个更高的层次称为实现描述,我们使用自然语言来描述图灵机如何移动其头部并将数据存储在磁带上。在这个级别,我们不提供状态或转换函数的详细信息。第三种选择是高级描述,我们使用自然语言来描述算法,忽略实现细节。在这个层面上,我们不需要解释机器如何处理其磁带或磁头。

The second, higher level is called the implementation description, in which we use natural language to describe how the Turing machine moves its head and how it stores data on the tape. At this level, we do not provide details of states or transition functions. The third possibility is the high-level description, in which we use natural language to describe the algorithm, ignoring implementation details. At this level, we do not need to explain how the machine operates its tape or head.

在本章中,我们提供了几个图灵机示例的正式和实现级描述。练习使用图灵机的低级描述可以帮助您了解它们的工作原理并更轻松地使用它们。一旦我们有信心,高级描述就足够了。

In this chapter, we have presented formal and implementation-level descriptions of several example Turing machines. Practicing with low-level descriptions of Turing machines helps us understand how they work and become comfortable using them. Once we feel comfortable, high-level descriptions will be sufficient.

我们现在将介绍用于描述图灵机的格式和符号。图灵机的输入始终是一个单词。如果我们想提供一个单词以外的对象作为输入,我们必须首先将该对象编码为单词。单词可以轻松地表示多项式、图形、语法、自动机以及此类对象的任意组合。可以对图灵机进行编程来解码该表示,以便可以按照我们想要的方式对其进行解释。用于将O对象编码为单词的符号是 O 。如果我们有许多对象O 1 , O 2 , …, O k,我们将把它们的编码写成单词O 1 , O 2 , …, O k。编码本身可以通过许多合理的方式完成。我们选择哪一种并不重要,因为图灵机总是可以将一种这样的编码转换为另一种编码。

We now present the format and notation used to describe Turing machines. The input to a Turing machine is always a word. If we want to provide an object other than a word as input, we must first encode that object as a word. Words can easily represent polynomials, graphs, grammars, automata, and any combination of such objects. A Turing machine can be programmed to decode this representation so that it can be interpreted in the way we intend. The notation used to encode an object O as a word is O . If we have multiple objects O 1 , O 2 , …, O k , we will write their encoding as a word O 1 , O 2 , …, O k . The encoding itself can be done in many reasonable ways. It does not matter which one we choose, since a Turing machine can always translate one such encoding into another.

在所使用的约定中,我们通过引号中的缩进文本来描述图灵机算法。我们将算法划分为多个步骤,每个步骤通常涉及一系列图灵机计算。我们用额外的缩进来标记算法的结构。算法的第一行描述了机器的输入。如果输入描述只是w,我们假设输入是一个单词。如果输入描述是一个编码对象,例如<A> 图灵机首先隐式测试输入是否以所需的形式正确编码该对象,如果没有,则丢弃数据。

The convention used is to describe Turing machine algorithms by indenting a section of text in quotation marks. We divide the algorithm into steps, each of which typically involves a sequence of Turing machine computations. We indicate the structure of the algorithm with additional indentation. The first line of the algorithm describes the input to the machine. If the description of the input is simply w , we assume that the input is a word. If the description of the input is an encoded object such as A , the Turing machine first implicitly tests whether the input correctly encodes the object in the desired form, and discards the data if it does not.

3.23

Example 3.23

A为表示无向连通图的所有单词的语言。回想一下,如果每个顶点都可以通过由图的边组成的路径从每个其他顶点到达,则图是连通的。我们将其另存为

Let A be the language of all words representing undirected connected graphs. Recall that a graph is connected if every vertex can be reached from every other vertex by a path consisting of the edges of the graph. We write this as

A = { G : G是连通无向图}。

A = { G : G is a connected undirected graph}.

以下是图灵机M解析A的高级描述。

Below is a high-level description of a Turing machine M that decides A .

M = "对于输入词G ,图编码G

M = "For an input word G , encoding a graph G :

  1. 选择第一个顶点G并为其添加标签。
  2. Select the first vertex G and label it.
  3. 重复以下步骤,直到没有标记新的顶点。
  4. Repeats the step below until no new vertices are labeled.
  5. 对于G中的每个顶点,如果它通过边连接到已标记的顶点,则对其进行标记。
  6. For each vertex in G , label it if it is connected by an edge to an already labeled vertex.
  7. 遍历G的所有顶点,判断是否全部都被标记了。如果是这样,请接受;否则丢弃。”
  8. Traverse all vertices of G to determine if all are labeled. If so, accept ; otherwise reject ".

作为额外的练习,让我们考虑机器M实现级别的一些细节。我们通常不会提供如此详细的描述,读者也不必这样做,除非练习中明确指出。首先,我们需要理解<G>如何将G编码单词。考虑一种编码,它是顶点G的列表,后跟边G的列表。每个顶点都有一个十进制数,每条边都是一对数字,代表该边两端的顶点。下图显示了这样一个图及其编码。

As an additional exercise, let us consider some implementation-level details of the machine M . We will not normally provide such a detailed description, and the reader is not required to do so unless explicitly indicated in the exercise. First, we need to understand how G encodes the graph G as a word. Consider an encoding that is a list of the vertices of G , followed by a list of edges of G . Each vertex has a decimal number, and each edge is a pair of numbers representing the vertices at either end of that edge. The following figure shows such a graph and its encoding.

3.24

G及其编码〈G〉

Figure 3.24

Graph G and its encoding G

M接收输入G 时,它首先检查输入是否是某个图的有效编码。为此,M浏览磁带以确保其中包含两个列表并且它们的形式正确。第一个列表应该是不同十进制数的列表,第二个列表应该是十进制数对的列表。M然后检查了一些事情。首先,顶点列表不能包含重复;其次,出现在边列表中的每个顶点也应该出现在顶点列表中。我们使用M 4机器的示例 3.12 中所示的程序检查第一个条件,该程序检查元素的可区分性。类似的方法适用于第二个条件。如果输入单词通过了这些测试,它就是某个图G的编码。此检查完成输入检查,M继续执行步骤 1。

When M receives input G , it first checks whether the input is a valid encoding of some graph. To do this, M scans the tape to make sure that it contains two lists and that they are in the correct form. The first list should be a list of distinct decimal numbers, and the second a list of pairs of decimal numbers. M then checks several things. First, the vertex list must not contain duplicates; second, any vertex appearing in the edge list should also appear in the vertex list. We check the first condition using the procedure shown in Example 3.12 for a machine M 4 , which checked for distinguishability of elements. An analogous method works for the second condition. If the input word passes these tests, it is an encoding of some graph G . This verification completes the input checking, and M moves on to step 1.

在步骤 1 中,机器M在左侧数字上用点标记第一个顶点。

In step 1, machine M marks the first vertex with a dot on the left digit.

在步骤 2 中,机器M浏览顶点列表以找到没有点的顶点,我们将其称为n 1,并以其他方式选择它 - 例如,通过突出显示第一个符号。然后M再次查看列表以找到点状顶点,我们将其称为n 2,并突出显示它。

In step 2, M traverses the list of vertices to find a vertex without a dot, call it n 1 , and marks it in a different way—for example, by underlining the first symbol. M then traverses the list again to find a vertex marked with a dot, call it n 2 , and underlines it as well.

现在M查看边列表。对于每条边,M检查两个带下划线的顶点n 1n 2是否是出现在该边上的顶点。如果是这种情况,M将n用1标记,删除下划线,然后返回到步骤 2 的开头。如果不是这种情况,M检查列表中的下一条边。如果没有更多的边,则意味着{ n 1 , n 2 }不是G的边。 M然后将下划线从n 2移动到带有点的下一个顶点,从此该顶点称为n 2。机器重复本段中的步骤来检查新的对{ n 1 , n 2 }是否是边缘。如果不再有点状顶点,则n 1不与任何点状顶点连接。在这种情况下,M设置下划线,使得n 1是下一个不带点的顶点,n 2是第一个带点的顶点,然后重复本段中的步骤。如果没有更多未点的顶点,则M无法找到任何新的点来点,因此转到步骤 4。

Now M scans the list of edges. For each edge, M checks whether the two underlined vertices n 1 and n 2 are the ones that appear in that edge. If they are, M marks n 1 with a dot, removes the underlines, and returns to the beginning of Step 2. If they are not, M checks the next edge in the list. If there are no more edges, this means that { n 1 , n 2 } is not an edge of G . M then moves the underline from n 2 to the next vertex with a dot, and from that point on, this vertex is called n 2 . The machine repeats the steps in this paragraph to check whether the new pair { n 1 , n 2 } is an edge. If there are no more vertices with dots, n 1 is not connected to any of the dotted vertices. In this situation, M sets the underscores so that n 1 is the next vertex without a dot and n 2 is the first vertex with a dot, and then repeats the steps in this paragraph. If there are no more vertices without dots, then M was unable to find any new vertices to label with a dot, so it goes to step 4.

在步骤4中,机器M查看节点列表以检查是否所有节点都被标记为点。如果是,则转入接受状态;否则进入拒绝状态。图灵机M的描述到此结束。

In step 4, the machine M scans the list of nodes to see if all of them are marked with a dot. If so, it enters the accepting state; otherwise, it enters the rejecting state. This completes the description of the Turing machine M .

练习

Exercises

3.1 本练习使用图灵机M 2,其描述和状态图如例 3.7 所示。在每个点上,呈现针对给定输入字运行时输入的配置序列。

3.1 This exercise uses the Turing machine M 2 , whose description and state diagram were given in Example 3.7. At each point, show the sequence of configurations it enters when run for a given input word.

0 .

a. 0 .

00

A b. 00 .

c.000

c. 000 .

d.000000

d.000000 .

3.2 本练习使用图灵机M 1,其描述和状态图见例 3.9。在每个点上,呈现在针对给定输入字运行时输入的配置序列。

3.2 This exercise uses the Turing machine M 1 , whose description and state diagram appear in Example 3.9. At each point, show the sequence of configurations it enters when run for a given input word.

11

A a. 11 .

1#1

b. 1#1 .

1## 1

c. 1##1 .

10 #11

d. 10#11 .

e. 10#10

e. 10#10 .

A 3.3 修改定理 3.16 的证明以获得推论 3.19,表明一种语言是可判定的当且仅当它可以被某个非确定性图灵机确定。 (您可以假设以下关于树的定理:如果树的每个顶点都有有限多个子节点,并且树的每个分支都有有限多个顶点,则整个树包含有限多个顶点。)

A 3.3 Modify the proof of Theorem 3.16 to obtain Corollary 3.19 by showing that a language is decidable if and only if it is decidable by some nondeterministic Turing machine. (You may assume the following theorem about trees: If each vertex of a tree has finitely many children and each branch of the tree has finitely many vertices, then the entire tree contains finitely many vertices.)

3.4 给出枚举数的正式定义。假设这是一种双磁带图灵机,使用第二条磁带作为打印机。包括枚举语言的定义。

3.4 Give a formal definition of an enumerator. Assume that it is a type of two-tape Turing machine that uses the second tape as a printer. Include a definition of the language being enumerated.

A 3.5 研究图灵机的正式定义,回答以下问题,解释你的推理。

A 3.5 Analyze the formal definition of a Turing machine to answer the following questions, explaining your reasoning.

a. 图灵机可以将空符号写入其磁带吗?

a. Can a Turing machine ever write the null symbol to its tape?

b. 磁带字母表Γ可以与输入字母表Σ相同吗?

b. Can the tape alphabet Γ be the same as the input alphabet Σ ?

c. 图灵机的头部可以在连续的两个步骤中处于相同的位置吗?

c. Can the head of a Turing machine ever be in the same position in two consecutive steps?

d. 图灵机只能包含一种状态吗?

d. Can a Turing machine contain just one state?

3.6 在定理 3.21 中,我们表明一种语言是图灵可识别的当且仅当它被某个计数器机器枚举时。为什么我们不使用下面更简单的算法来证明正确的含义?如前所述,s 1 , s 2 , … 是属于Σ *的所有单词的列表。

3.6 In Theorem 3.21 we showed that a language is Turing recognizable if and only if it is computed by some computing machine. Why didn't we use the following simpler algorithm to prove the right implication? As before, s 1 , s 2 , … is a list of all words belonging to Σ * .

E =“忽略输入。

E = "Ignore input.

a.对于i = 1, 2, 3, … 重复以下步骤

a. Repeat the following steps for i = 1, 2, 3, …

b .对s 运行M。

b. Run M for s and .

c. 如果M接受,则打印单词s"。

c. If M accepts, print the word s and ”.

3.7 解释为什么以下内容不是有效图灵机的描述。

3.7 Explain why the following is not a description of a correct Turing machine.

M bad = "对于输入词p ,其中p是变量x 1 , …, x k的多项式:

M bad = "For input word p , where p is a polynomial of variables x 1 , …, x k :

a. 尝试对变量x 1 , …, x k进行所有可能的整数赋值。

a. Try all possible integer value assignments for variables x 1 , …, x k .

b. 计算每个分配的p 。

b. Calculate p for each of these assignments.

c. 如果这些赋值中的任何一个赋值为 0,则接受;否则丢弃。”

c. If any of these assignments evaluates to 0, accept ; otherwise reject ."

3.8 提供以下语言通过字母表{0,1}解析的图灵机的实现级描述。

3.8 Give implementation-level descriptions of Turing machines that resolve the following languages ​​over the alphabet {0,1}.

A a. { w : w包含相同数量的 0 和 1}

A a. { w : w contains an equal number of zeros and ones}

b. { w : w包含的零数量是 1 的两倍}

b. { w : w contains twice as many zeros as ones}

c. { w : w包含的零数量不等于 1 的两倍}

c. { w : w does not contain twice as many zeros as ones}

问题

Problems

3.9k -PDA 为具有k 个堆栈的自动机。因此,0-PDA是非确定性有限自动机,1-PDA是正则PDA。我们已经知道 1-PDA 比 0-PDA 更强(识别更多类别的语言)。

3.9 Let k -PDA be an automaton with k stacks. Thus, 0-PDA is a nondeterministic finite automaton, and 1-PDA is a conventional PDA. We already know that 1-PDAs are more powerful (they recognize a larger class of languages) than 0-PDAs.

a. 证明2-PDA 比1-PDA 更强。

a. Prove that 2-PDAs are stronger than 1-PDAs.

b. 证明3-PDA并不比2-PDA强。 (提示:使用两个堆栈模拟图灵机磁带。)

b. Prove that 3-PDAs are no stronger than 2-PDAs. (Hint: Simulate a Turing machine tape using two stacks.)

A 3.10 一次写入图灵是一种单磁带图灵机,最多可以更改一次磁带每个字段的内容(包括磁带上包含输入字的部分)。证明图灵机模型的这个变体与标准模型是等价的。 (提示:第一步,考虑图灵机最多可以修改磁带每个字段两次的情况。使用大量磁带。)

A 3.10 A write-once Turing machine is a single-tape Turing machine that can modify the contents of each field of the tape at most once (including the part of the tape containing the input word). Show that this variant of the Turing machine model is equivalent to the standard model. (Hint: As a first step, consider the case in which the Turing machine can modify each field of the tape at most twice. Use a lot of tape.)

3.11 双面无限带图灵机与正则图灵机相似,但其带在左侧也是无限的,而不仅仅是右侧。除了包含输入单词的部分之外,磁带最初填充有空白符号。计算的定义与往常一样,只是磁头向左移动时不会碰到磁带的末端。表明这种类型的图灵机可以识别一类图灵可识别的语言。

3.11 A Turing machine with a double-sided infinite tape is similar to an ordinary Turing machine, but its tape is also infinite on the left side, not just on the right. The tape is initially filled with null symbols, except for the part containing the input word. The computation is defined as usual except that the head never encounters the end of the tape as it moves to the left. Show that this type of Turing machine recognizes the class of Turing-recognizable languages.

3.12 跳转启动图灵机与正则图灵机类似,但转换函数为

3.12 A jump-start Turing machine is similar to an ordinary Turing machine, but the transition function has the form

δ : Q × Г Q × Г × { R , 重置 }。

δ : Q × Γ Q × Γ × { R , RESET}.

如果 δ( q , a ) = ( r , b , RESET) ,则当状态q的机器读取a时,磁头在磁带上写入符号b,然后跳到其左端并进入状态r。请注意,这些机器没有将头部向左移动一个符号的标准操作。证明跳跃优先图灵机可以识别一类图灵可识别的语言。

If δ( q , a ) = ( r , b , RESET), then when a machine in state q reads a , the head writes the symbol b to the tape, then jumps to the left end of the tape and enters state r . Note that these machines do not have the standard operation of moving the head one symbol to the left. Show that Turing machines with a jump to the front recognize the class of Turing-detectable languages.

3.13 停止而不是左移的图灵机正则图灵机类似,但其转换函数

3.13 A Turing machine with halting instead of moving left is similar to an ordinary Turing machine, but its transition function has the form

δ : Q × Г Q × Г × { R ,S}。

δ : Q × Γ Q × Γ × { R , S}.

在每个点,机器都可以将头部移动到右侧或保持在同一位置。证明这个变体不等同于普通版本。这些机器能识别哪一类语言?

At each point the machine can move the head to the right or remain in the same position. Show that this variant is not equivalent to the usual version. What class of languages ​​do such machines recognize?

3.14 队列机与堆栈机类似,只不过堆栈被队列代替。队列是一盘磁带,符号只能写入到左端,只能从右端读取。每个写操作(称为“入队”)都会向队列的左端添加一个符号,每个读操作(“出队”)会从右端读取并删除一个符号。与 PDA 一样,输入数据放置在单独的只读磁带上,并且该磁带上的磁头仅从左向右移动。磁带在输入数据后面包含一个空白字段,以便可以检测到数据的结尾。排队机接受输入字,随时进入特殊的接受状态。表明一种语言可以被确定性排队自动机识别当且仅当它是图灵可识别的语言。

3.14 A queued automaton is similar to a stacked automaton except that the stack is replaced by a queue. A queue is a tape onto which symbols can be added only to the left end and read only from the right end. Each write operation (call it “enqueueing”) adds a symbol to the left end of the queue, and a read operation (“dequeuing”) reads and removes a symbol from the right end. As with a PDA, the input data is placed on a separate read-only tape, and the head on this tape moves only from left to right. The tape contains a field with a null symbol following the input data, which allows the end of data to be detected. A queued automaton accepts an input word, entering a special accepting state at any time. Show that a language can be recognized by a deterministic queued automaton if and only if it is a Turing-recognizable language.

3.15 证明可判定语言集合对于操作而言是封闭的

3.15 Show that the set of decidable languages ​​is closed under the operations

总和

A a. sums.

b. 串联。

b. concatenation.

c. 星号(Kleene 闭包)。

c. asterisks (Kleene closures).

d. 补充。

d. complements.

e. 交叉点。

e. intersections.

3.16 证明图灵可识别的语言集合在运算方面是封闭的

3.16 Show that the set of Turing-recognizable languages ​​is closed under the operations

啊。 总和。

Aa. sums.

b. 串联。

b. concatenation.

c. 星号(Kleene 闭包)。

c. asterisks (Kleene closures).

d. 交叉点。

d. intersections.

同态

e. homomorphism.

*3.17B = { M 1 , M 2 , …} 是由图灵机描述组成的图灵可识别语言。证明存在一种包含图灵机描述的可判定语言C,使得B中描述的每个机器在C中都有一个等效的机器,反之亦然。

*3.17 Let B = { M 1 , M 2 , …} be a Turing-decidable language composed of descriptions of Turing machines. Show that there is a decidable language C containing descriptions of Turing machines such that every machine described in B has an equivalent machine in C , and vice versa.

*3.18 表明当且仅当某个枚举器按标准字典顺序枚举该语言时,该语言是可判定的。

*3.18 Prove that a language is decidable if and only if some enumerator enumerates that language in the standard lexicographic order.

*3.19 证明每种无限图灵可识别语言都包含无限可判定子集。

*3.19 Prove that every infinite Turing-recognizable language contains an infinite decidable subset.

*3.20 表明单磁带图灵机无法写入包含输入单词的磁带部分,只能识别正则语言。

*3.20 Show that a single-tape Turing machine that cannot write the part of the tape containing the input word recognizes only regular languages.

3.21c 1 x n + c 2 x n −1 +·… + c n x + c n +1为根为x 0的多项式。令c max为系数c中的最大绝对值。证明

3.21 Let c 1 x n + c 2 x n −1 + · … + c n x + c n +1 be a polynomial whose root is x 0 . Let c max be the largest absolute value of the coefficients c and . Prove that

A 3.22A为仅包含单个单词s 的语言,使得

A 3.22 Let A be a language containing only a single word s , such that

A是可判定的吗?为什么是或为什么不是?出于此问题的目的,假设火星上是否会发现生命的问题有明确的“是”或“否”答案。

Is A decidable? Why yes or no? For the purposes of this problem, assume that the question of whether life will be found on Mars has an unambiguous answer of YES or NO.

精选解决方案

Selected solutions

3.1 ( b ) q 1 00 , q 2 0 , x q 3 , q 5 x , q 5 x , q 2 x , x q 2 , x q接受

3.1 ( b ) q 1 00 , q 2 0 , x q 3 , q 5 x , q 5 x , q 2 x , x q 2 , x q accept .

3.2 ( a ) q 1 11 , x q 3 1 , x 1 q 3 , x1 q拒绝

3.2 ( a ) q 1 11 , x q 3 1 , x 1 q 3 , x1 q reject .

3.3 我们证明了两个方向的含义。首先,如果语言L是可判定的,那么它可以被确定性图灵机识别,从而自动被非确定性图灵机识别。

3.3 We will prove both directions of the implication. First, if the language L is decidable, then it can be recognized by a deterministic Turing machine, and hence automatically by a nondeterministic Turing machine.

其次,如果某个非确定性图灵机N解析了语言L,那么我们可以根据定理 3.16 的证明修改确定性图灵机D如下:

Second, if some nondeterministic Turing machine N decides the language L , then we can modify the deterministic Turing machine D from the proof of Theorem 3.16 as follows:

我们将步骤 4 移至步骤 5。

We are moving step 4 to become step 5.

我们添加一个新的步骤 4:如果所有非确定性N 个计算路径都已被丢弃,则丢弃。

We add a new step 4: Reject if all N nondeterministic computation paths have been rejected.

我们声称这台新机器D'解决了L 问题。如果N接受其输入,D'最终将找到一条接受路径并接受。如果N丢弃输入,则其所有路径都会终止并丢弃,因为它是决胜局机器。因此,每条路径具有有限多个顶点,其中每个顶点代表该路径上N次计算的一步。因此,该输入的整个计算树N由练习公式中给出的树定理有限。因此,当整个树都被探索过时,D'将停止并拒绝输入。

We claim that this new machine D' resolves L . If N accepts its input, D' will eventually find an accepting path and also accept. If N rejects the input, all of its paths terminate and reject, since it is a resolver. Thus, each path has finitely many vertices, where each vertex represents one computation step of N on that path. Thus, the entire tree of computations of N for that input is finite by the tree theorem given in the exercise formulation. Consequently, D' will halt and reject the input once the entire tree has been explored.

3.5 ( a ) 是。磁带字母表Γ包含。图灵机可以将字母表Γ中的任何字符写入Tape 。

3.5 ( a ) Yes. The tape alphabet Γ contains . A Turing machine can write any characters from the alphabet Γ onto the tape .

( b ) 没有。Σ从不包含,但gamma始终包含。因此,这些字母不可能相等。

( b ) No. Σ never contains , but Γ always contains . Hence, these alphabets cannot be equal.

( c ) 是的。如果图灵机尝试将磁头移动到磁带开头的左侧,它将保留在磁带的同一区域。

( c ) Yes. If the Turing machine tries to move the head to the left of the beginning of the tape, it will stay on the same field of the tape.

( d ) 没有。每个图灵机必须包含两个不同的状态:q Acceptq Reserve。因此图灵机必须至少包含两个状态。

( d ) No. Every Turing machine must contain two distinct states: q accept and q reject . So a Turing machine must contain at least two states.

3.8 ( a ) '对于输入词

3.8 ( a ) "For input word in :

1. 从左到右浏览磁带并标记先前未标记的第一个0 。如果未找到未标记的0,请转至步骤 4。否则,将磁头移回到磁带的开头。

1. Scan the tape from left to right and mark the first 0 that was not previously marked. If you do not find an unmarked 0 , go to step 4. Otherwise, move the head back to the beginning of the tape.

2. 浏览磁带并标记之前未标记的第一个磁带。如果您没有找到任何未标记的1请丢弃

2. Look through the tape and label the first 1 that has not been previously labeled. If you do not find any unlabeled 1 , discard .

3. 将磁头移回磁带开头并转至步骤 1。

3. Move the head back to the beginning of the tape and go to step 1.

4. 将磁头移动到磁带的开头。浏览磁带,看看是否还有未标记的1。如果没有找到,请接受;否则丢弃。”

4. Move the head to the beginning of the tape. Browse the tape to see if there are any unmarked 1's left . If none are found, accept ; otherwise, reject ."

3.10 首先,我们将在两次写入机器上模拟正则图灵机。两次写入机器通过将整个磁带复制到当前使用的部分右侧的磁带空白部分来模拟原始机器的单个步骤。复制过程是逐字符进行的,在复制时标记字符。此过程将磁带的每个字段更改两次:一次是第一次记录字符,另一次将其标记为已复制。磁带上标出了原机磁头的位置。当您复制标记或相邻位置的字段时,磁带的内容将根据原始图灵机的规则进行更新。

3.10 First, we simulate an ordinary Turing machine on a double-write machine. The double-write machine simulates a single step of the original machine, copying the entire tape to a blank part of the tape to the right of the currently used part. The copying procedure is performed character by character, marking the characters as they are copied. This procedure changes each field of the tape twice: once to write the character the first time, and again to mark it as copied. The position of the original machine's head is marked on the tape. As fields at or adjacent to the marked position are copied, the tape contents are updated according to the rules of the original Turing machine.

为了模拟一次写入机器,我们进行类似的操作,只是前一个磁带的每个字段现在由两个字段表示。第一个包含来自原始机器磁带的符号,第二个用于复制过程中使用的标签。输入数据不会以每个符号两个字段的格式传递到机器,因此首次复制磁带时,复制标记会直接放置在输入符号上方。

To simulate it on a write-once machine, we proceed analogously except that each field of the previous tape is now represented by two fields. The first contains the symbol from the original machine's tape, and the second is used for the token used in the copy procedure. The input data is not passed to the machine in a two-field-per-symbol format, so the first time the tape is copied, the copy tokens are placed immediately above the input symbols.

3.15 ( a )对于任意两种可判定语言L 1L 2 ,M 1M 2为判定它们的图灵机。我们将构建一个图灵机M'来解析语言L 1L 2的总和:

3.15 ( a ) For any two decidable languages ​​L 1 and L 2 , let M 1 and M 2 be Turing machines that decide them. We construct a Turing machine M' that decides the union of the languages ​​L 1 and L 2 :

“对于输入单词

"For input word in :

1.对中的输入字 运行M 1。如果本机接受,则接受

1. Run M 1 for input word w . If this machine accepts, accept .

2.对中的输入字 运行M 2。如果本机接受,则接受。否则,丢弃。”

2. Run M 2 for input word w . If this machine accepts, accept . Otherwise reject ”.

如果机器M 1M 2之一接受 w,则M'接受w 。如果两者都拒绝w,则M'拒绝。

M' accepts w if either of the machines M 1 or M 2 accepts it. If both reject w , then M' rejects.

3.16 ( a ) 对于任意两种图灵可识别语言L 1L 2 ,令M 1M 2为识别它们的图灵机。我们将构建一个图灵机M'来识别语言L 1L 2的总和:

3.16 ( a ) For any two Turing-recognizable languages ​​L 1 and L 2 , let M 1 and M 2 be Turing machines that recognize them. We construct a Turing machine M' that recognizes the union of the languages ​​L 1 and L 2 :

“对于输入单词

"For input word in :

1.交替、逐步的方式对输入字 执行M 1M 2机器计算。如果达到接受状态,则接受。如果两者都停止并拒绝,就拒绝。”

1. Perform computations on machines M 1 and M 2 for input word w alternately, step by step. If one of them reaches an accepting state, accept . If both stop and reject, reject ”.

如果机器M 1M 2之一接受w则 M'接受w,因为接受图灵机在有限数量的步骤后达到接受状态。请注意,如果两台机器M 1M 2都不接受该输入,并且其中一台机器通过循环接受该输入,则M'也会循环。

If either of the machines M 1 and M 2 accepts w , M' accepts w , since the accepting Turing machine reaches the accepting state after a finite number of steps. Note that if both the machines M 1 and M 2 do not accept this input and one of them does so by looping, then M' will also loop.

3.22 语言A是两种语言{0}或{1}之一。在每种情况下,这种语言都是有限的,因此是可判定的。如果我们无法确定A是这两种语言中的哪一种,那么我们将无法描述解析A 的机器。然而,我们可以表示两台图灵机,其中一台是解析器机A。

3.22 Language A is one of two languages ​​{0} or {1}. In each case, the language is finite and hence decidable. If we cannot determine which of the two languages ​​A is , then we cannot describe a machine that decides A . However, we can represent two Turing machines, one of which is a machine that decides A .

4

可判定性

4.

Decidability

在第三章中,我们根据丘奇-图灵假设,使用图灵机的概念,介绍了图灵机作为通用计算机模型,并定义了算法的概念。

In Chapter 3 we introduced the Turing machine as a model of a general-purpose computer and defined the notion of an algorithm using the concept of Turing machines in accordance with the Church–Turing hypothesis.

在本章中,我们将开始探索可以通过算法解决哪些问题。我们将展示有算法可以解决的问题以及无法通过这种方式解决的问题的示例。我们的目标是了解使用算法解决问题的局限性。读者可能遇到过使用算法解决问题的情况,因为大多数计算机科学都致力于解决问题。然而,某些问题的无法解决可能会令人惊讶。

In this chapter, we begin to explore what problems can be solved algorithmically. We provide examples of problems for which there are algorithms that solve them, and examples of problems that cannot be solved algorithmically. Our goal is to explore the limits of what can be solved using algorithms. You have probably encountered solving problems using algorithms, since most of computer science is devoted to solving problems. However, the unsolvability of some problems may come as a surprise.

我们为什么要关心不可解性?最终,如果我们需要解决问题,那么证明问题无法解决似乎并没有多大用处。这种现象值得研究,原因有二。首先,知道问题何时在算法上无法解决是有用的,因为它可以帮助我们理解在寻求算法解决方案之前需要简化或修改问题。与任何其他工具一样,计算机具有一定的功能,但如果要正确使用计算机,也必须考虑到其局限性。第二个原因是文化。即使我们正在处理明显可以解决的问题,看待一个无法解决的问题也可以激发想象力,并以更广阔的视角展示计算问题。

Why should we care about unsolvability? After all, showing that a problem is unsolvable does not seem particularly useful if we have to solve it. The phenomenon is worth studying for two reasons. First, knowing when a problem is algorithmically unsolvable is useful because it allows us to understand the need to simplify or modify the problem before we can seek an algorithmic solution. Like any other tool, computers have capabilities but also limitations that must be taken into account if they are to be used properly. The second reason is cultural. Even when we are dealing with problems that are obviously solvable, looking at an unsolvable problem can stimulate the imagination and put the problem of computation in a broader perspective.

4.1

可判定语言

4.1

Decidable languages

在本节中,我们将介绍一些可由算法判定的语言示例。我们将重点关注与自动机和语法相关的语言。例如,我们将提出一种算法来测试给定单词是否是上下文无关语言(CFL)的元素。出于多种原因,此类语言很有趣。首先,此类问题的一些与特定应用有关。检查给定的上下文无关语法(CFG)是否生成给定单词的问题与识别和编译用某种编程语言编写的程序的问题有关。其次,存在一些关于自动机和语法的问题是算法无法判定的。从可判定性可能的例子开始将使我们能够理解不可判定性的情况。

In this section, we will present several examples of languages ​​that are decidable by algorithms. We will focus on languages ​​that deal with automata and grammars. For example, we will present an algorithm that tests whether a given word is an element of a context-free language (CFL). Such languages ​​are interesting for several reasons. First, some of these problems are related to specific applications. The problem of testing whether a given context-free grammar (CFG) generates a given word is related to the problem of recognizing and compiling programs written in a programming language. Second, there are some problems involving automata and grammars that are not decidable by algorithms. Starting with examples where decidability is possible will help us appreciate the cases of undecidability.

涉及正则语言的可判定问题

Decidable problems involving regular languages

我们将从涉及有限自动机的选定计算问题开始。我们将提出算法来检查有限状态机是否接受给定的单词、有限状态机的语言是否为空以及两个有限状态机是否等效。

We will start with selected computational problems concerning finite automata. We will present algorithms to check whether a finite automaton accepts a given word, whether the language of the finite automaton is empty, and whether two finite automata are equivalent.

请注意,我们选择使用语言来表示计算问题。这很方便,因为我们已经定义了使用语言的术语。例如, DFA 的接受问题,即测试特定的确定性有限自动机是否接受给定的单词,可以表示为DFA语言。该语言包含所有 DFA 的编码以及这些自动机接受的单词。让

Note that we have chosen to represent computational problems using languages. This procedure is convenient because we have already defined the terminology for using languages. For example, the acceptance problem for a DFA, that is, testing whether a given deterministic finite automaton accepts a given word, can be formulated as the language A DFA . This language contains the encodings of all DFAs together with the words accepted by them. Let

A DFA = { B , w B是接受输入单词w }的 DFA 。

A DFA = { B , w : B is a DFA that accepts input word w }.

检查 DFA B是否接受输入词w 的问题与检查< B , w >是否属于语言A DFA的问题相同。类似地,我们可以将其他计算问题表述为测试某种语言的成员资格。显示语言是可判定的与显示某个计算问题是可判定的相同。

The problem of testing whether a DFA B accepts an input word w is the same as the problem of testing whether B , w belongs to the DFA language A . Similarly, we can formulate other computational problems as testing membership in some language. Showing that a language is decidable is the same as showing that a computational problem is decidable.

在下面的定理中,我们将证明A DFA语言是可判定的。因此,该定理表明检查给定有限自动机是否接受给定单词的问题是可判定的。

In the following theorem we will show that the language A DFA is decidable. Thus, this theorem shows that the problem of checking whether a given finite automaton accepts a given word is decidable.

定理4.1

Theorem 4.1

DFA一种可判定语言。

And DFA is a decidable language.

证明的概念 我们只需要提供一个图灵机M来解析A DFA语言。

Concept of Proof We simply need to represent a Turing machine M that decides the DFA language A .

M = "对于输入单词B , w ,其中B是 DFA,w是单词:

M = "For input word B , w , where B is a DFA and w is a word:

  1. 中的输入词模拟自动机B。
  2. Simulate automaton B for input word w .
  3. 如果模拟以接受状态结束,则接受。如果它以不接受状态结束,则丢弃。”
  4. If the simulation ends in an accepting state, accept . If it ends in an unaccepting state, reject ."

证明 我们将仅介绍该证明的一些实现细节。那些具有使用任何标准编程语言编写程序经验的读者可以想象他们将如何编写程序来执行此模拟。

Proof We will present only a few implementation details of this proof. Those readers who have experience writing programs in any standard programming language can imagine how they would write a program to perform this simulation.

首先我们需要检查输入单词B , w 。这是B与单词w组合的DFA 表示。B 的合理表示只是其五个分量的列表:QΣ、 δ 、q 0F。当机器M收到输入时,它首先检查该单词是否正确表示 DFA B和单词w。如果不是这种情况,M就会丢弃输入单词。

First, we need to examine the input word B , w . This is the DFA representation of B combined with the word w . A reasonable representation of B is simply a list of its five components: Q , Σ , δ, q 0 , and F . When a machine M receives its input, it first checks whether this word correctly represents the DFA of B , and the word w . If it does not, M discards the input word.

然后M直接进行模拟。它跟踪机器B的当前状态及其在输入字中的位置,并将此信息记录在磁带上。最初, B的当前状态是q 0,输入字中的当前位置是最左边的符号w。状态和位置根据给定的传递函数 δ 进行更新。当M处理完单词的最后一个符号时,如果B处于接受状态,则它接受输入单词,否则拒绝它。

Then M directly performs the simulation. It keeps track of the current state of B and its position in the input word, recording this information on the tape. Initially, the current state of B is q 0 , and the current position in the input word is the leftmost symbol w . The states and position are updated according to the given transition function δ. When M has finished processing the last symbol of w , it accepts the input word if B is in an accepting state, otherwise it rejects it.

我们可以为非确定性有限自动机证明类似的定理。让

We can prove a similar theorem for nondeterministic finite automata. Let

A NFA = { B , w B是接受输入单词w }的 NFA 。

A NFA = { B , w : B is an NFA that accepts input word w }.

定理4.2

Theorem 4.2

NFA一种可判定语言。

And NFA is a decidable language.

证明 我们将提出一个图灵机N来解析A NFA语言。我们可以将N设计为像M一样工作,模拟 NFA 而不是 DFA。然而,我们会以不同的方式来说明一个新概念:我们将使用M作为N的子程序由于M被设计为在确定性有限自动机上运行,​​因此N会将输入 NFA 转换为等效的 DFA,然后将其传递给M

Proof We will present a Turing machine N that resolves a language A NFA . We could design N to act just like M , simulating an NFA rather than a DFA. However, we will do it differently to illustrate the new idea: we will use M as a subroutine of N . Since M was designed to operate on deterministic finite automata, N will transform the NFA it receives as input into an equivalent DFA, and then pass it to M .

N = "对于输入单词B , w ,其中B是 NFA,w是单词:

N = "For input word B , w , where B is an NFA and w is a word:

  1. 使用定理 1.39 中给出的转换过程将 NFA B转换为等效的 DFA C。
  2. Transform NFA B into an equivalent DFA C using the transformation procedure given in Theorem 1.39.
  3. 根据定理 4.1启动机器M ,输入单词C , w
  4. Run the machine M by Theorem 4.1 for input word C , w .
  5. 如果机器M接受,则接受;否则丢弃。”
  6. If machine M accepts, accept ; otherwise reject ."

步骤2中启动机器M意味着将M作为子程序包含在程序N中。

Starting machine M in step 2 means including M in program N as a subroutine.

以类似的方式,我们可以确定正则表达式是否生成给定的单词。设A REX = { R , w R是生成单词w } 的正则表达式。

In a similar way, we can determine whether a regular expression generates a given word. Let A REX = { R , w : R is a regular expression that generates the word w }.

定理4.3

Theorem 4.3

REX一种可判定语言。

And REX is a decidable language.

证明 以下图灵机P解析语言A REX

Proof The following Turing machine P decides the language A REX .

P = "对于输入单词R , w ,其中R是正则表达式,w是单词:

P = "For input word R , w , where R is a regular expression and w is a word:

  1. 使用定理 1.54 中给出的转换过程将正则表达式R转换为其等效的 NFA A。
  2. Transform the regular expression R into its equivalent NFA A using the transformation procedure given in Theorem 1.54.
  3. 为输入词A , w 启动图灵机N
  4. Run a Turing machine N for input word A , w .
  5. 如果N接受,则接受;如果N拒绝,则拒绝”。
  6. If N accepts, accept ; if N rejects, reject ."

定理 4.1、4.2 和 4.3 说明,出于可判定性的目的,表示 DFA、NFA 或正则表达式的图灵机是等效的,因为机器可以将一种编码形式转换为另一种编码形式。

Theorems 4.1, 4.2, and 4.3 illustrate that for the purposes of decidability, the Turing machine representation of a DFA, NFA, or regular expression is equivalent, since the machine can transform one encoding form into another.

现在我们转向另一个有限自动机问题:有限自动机语言的空性检查。在前面的三个定理中,我们必须确定有限自动机是否接受特定的单词。在下一个证明中,我们需要确定这个有限自动机是否接受任何单词。让

We now turn to another problem concerning finite automata: checking for emptiness for the language of a finite automaton. In the preceding three theorems, we had to establish whether a finite automaton accepts a particular word. In the next proof, we have to establish whether this finite automaton accepts any words at all. Let

E DFA = { A A是 DFA 并且L ( A ) = Ø }。

E DFA = { A : A is DFA and L ( A ) = Ø }.

定理4.4

Theorem 4.4

E DFA是一种可判定语言。

E DFA is a decidable language.

当且仅当从初始状态开始并遵循该 DFA 的箭头可以达到接受状态时, DFA证明才会接受某个单词。为了测试这个条件,我们可以使用类似于示例 3.23 中使用的标记算法来构建图灵机T。

A DFA proof accepts a word if and only if it is possible to reach an accepting state by starting from the initial state and following the arrows of the DFA. To test this condition, we can construct a Turing machine T using a marking algorithm similar to the one used in Example 3.23.

T = "对于输入词A ,其中A是 DFA:

T = "For input word A , where A is the DFA:

  1. 标记初始状态A。
  2. Label the initial state A .
  3. 重复以下步骤,直到没有标记新状态。
  4. Repeat the step below until no new states are marked.
  5. 标记从已标记的任何状态访问的任何状态。
  6. Label each state that is a transition from any state that has already been labeled.
  7. 如果没有标记接受状态,则接受;否则丢弃。”
  8. If no accepting state is marked, accept ; otherwise reject ."

下一个定理是确定两个确定性有限自动机是否识别相同语言是可判定的。让

The next theorem states that determining whether two deterministic finite automata recognize the same language is decidable. Let

EQ DFA = { A , B | A和 B是DFA并且L ( A )= L ( B )}。

EQ DFA = { A , B | A and  B are DFA and L ( A ) = L ( B )}.

定理4.5

Theorem 4.5

EQ DFA是一种可判定语言。

EQ DFA is a decidable language.

证明 为了证明这个定理,我们将使用定理4.4。我们将基于自动机A和 B构造一个新的 DFA C,使得C只接受AB接受的单词,但不接受两者都接受的单词。因此,如果A和 B识别相同的语言,那么C将不会接受任何单词。自动机的语言是C

Proof To prove this theorem, we use Theorem 4.4. We construct a new DFA C from automata A and  B such that C accepts only those words that are accepted by either A or B , but not both. So, if A and  B recognize the same language, then C will not accept any words. The language of automaton C is

L ( C ) =( L ( A ) ∩L ( B ) ) ( L ( A ) ∩L ( B ) )。

L ( C ) = ( L ( A ) L ( B ) ) ( L ( A ) L ( B )).

该表达式有时称为对称差 L ( A ) 和L ( B ) ,如下图所示。L ( A )是L ( A )的补集。对称差在我们的例子中很有用,因为当且仅当L ( A ) = L ( B ) 时L ( C ) = Ø。我们将从自动机A和 B构造一个自动机C,使用正则语言类在补、并和交方面是封闭的证明的构造。这些构造是可以由图灵机执行的算法。构造完C后,我们可以利用定理 4.4 来检查L ( C ) 是否为空。如果是,则L ( A ) 和L ( B ) 必须相等。

This expression is sometimes called the symmetric difference of L ( A ) and L ( B ) and is illustrated in the figure below. L ( A ) is the complement of L ( A ). The symmetric difference is useful in our case, since L ( C ) = Ø if and only if L ( A ) = L ( B ). We construct the automaton C from the automata A and  B using constructions from the proofs that the class of regular languages ​​is closed under complement, union, and intersection. These constructions are algorithms that can be executed by Turing machines. Once C is constructed , we can use Theorem 4.4 to check whether L ( C ) is empty. If it is, L ( A ) and L ( B ) must be equal.

F = "对于输入词A , B ,其中A和 B是 DFA:

F = "For input word A , B , where A and  B are DFA:

  1. 按所述构建 DFA C。
  2. Construct DFA C as described.
  3. 从定理 4.4启动T机,输入单词C
  4. Run the machine T from Theorem 4.4 for input word C .
  5. 如果T接受,则接受。如果T拒绝,则拒绝
  6. If T accepts, accept . If T rejects, reject ."

4.6

对称差L ( A )和L ( B )

Figure 4.6

Symmetric difference of L ( A ) and L ( B )

上下文无关语言的可判定问题

Decidable problems involving context-free languages

在本节中,我们描述用于确定特定 CFG 语法是否生成特定单词以及检查 CFG 语言是否为空的算法。让

In this section we describe algorithms for determining whether a certain CFG grammar generates a given word, and for checking whether the CFG language is empty. Let

CFG = { G , w : G是生成单词w }CFG 语法。

A CFG = { G , w : G is a CFG grammar generating word w }.

定理4.7

Theorem 4.7

CFG一种可判定语言。

And CFG is a decidable language.

证明的概念 我们想要确定,对于某个 CFG 语法G和单词w G是否生成w。最初的想法可能是使用G循环遍历所有引脚以确定其中一个是否是中的引脚。这个概念行不通,因为您最终可能不得不尝试无限多个推导。如果G没有生成w,这个算法将永远不会停止。这个概念允许您创建一个识别但不解析A CFG语言的图灵机。

Proof Concept We want to determine for some CFG grammar G and a word w , whether G generates w . An initial idea might be to use G to iterate through all the derivations to determine whether one of them is a derivation w . This concept won't work, since it might turn out that we have to try infinitely many derivations. If G didn't generate w , the algorithm would never halt. This concept allows us to construct a Turing machine that recognizes, but does not resolve, the language A of the CFG .

为了将这台图灵机变成决定性的机器,我们需要确保算法尝试有限多次推导。在问题 2.26(第 157 页)中,我们表明如果G是乔姆斯基范式,则单词w的任何推导都包含 2 − 1 个步骤,其中n是w的长度。在这种情况下,为了确定G是否生成w,只需检查长度不大于 2n −  1 的导数就足够了。这样的导数只有有限多个。我们可以使用 2.1 节中介绍的过程将G转换为乔姆斯基范式。

To make this Turing machine decisive, we need to ensure that the algorithm tries finitely many derivations. In Problem 2.26 (page 157) we showed that if G is in Chomsky normal form, then any derivation of w takes 2n −  1 steps, where n is the length of w . In this case, to determine whether G generates w , it is sufficient to check only derivations of length no greater than 2n −  1. There are only finitely many such derivations. We can transform G into Chomsky normal form using the procedure presented in Section 2.1.

证明A CFG语言的 图灵机S如下所示。

Proof A Turing machine S for the language A CFG is given below.

S = "对于输入单词G , w ,其中G是上下文无关语法,w是单词:

S = "For an input word G , w , where G is a context-free grammar and w is a word:

  1. 将G转换为乔姆斯基范式的等效语法。
  2. Convert G to an equivalent Chomsky normal form grammar.
  3. 列出具有 2 n  − 1 步的所有推导,其中n是w的长度,除了n = 0 的情况- 然后列出具有一步的所有推导。
  4. Print all derivations of 2n −  1 steps, where n is the length of w , except for the case n = 0, in which case print all derivations of one step.
  5. 如果这些推导中的任何一个生成w则接受;如果不是,则丢弃
  6. If any of these derivations generates w , accept ; if not, reject ".

确定给定的上下文无关语法是否生成特定单词的问题与编译编程语言的问题有关。S机算法效率很低,不适合实际应用,但它很容易描述,这里我们不关心效率。在本书的第三部分中,我们将解决与算法的执行时间和内存消耗相关的问题。在定理 7.16 的证明中,我们将描述一种更有效的算法来识别一般上下文无关语言。当识别确定性上下文无关语言时,甚至可以实现更高的性能。

The problem of determining whether a given context-free grammar generates a given word is related to the problem of compiling programming languages. The S machine algorithm is very inefficient and unsuitable for practical applications, but it is easy to describe, and we do not concern ourselves with performance here. In Part 3 of this book we will deal with the problems of execution time and memory consumption of the algorithms. In the proof of Theorem 7.16 we describe a more efficient algorithm for recognizing general context-free languages. Even higher performance is possible for recognizing deterministic context-free languages.

我们记得,在定理 2.20 中,我们提出了将 CFG 语法转换为 PDA 的过程,反之亦然。因此,我们可以说的关于 CFG 语法问题的可判定性的一切都同样适用于 PDA。

As we recall, in Theorem 2.20 we presented procedures for transforming CFG grammars into PDAs and vice versa. Thus, everything we can say about the decidability of problems involving CFG grammars applies equally to PDAs.

现在让我们转向检查上下文无关语法生成的语言的空性问题。与 DFA 一样,我们可以证明确定 CFG 语法是否生成任何单词的问题是可判定的。让

Let us now turn to the problem of checking the emptyness of a language generated by a context-free grammar. As in the case of DFA, we can show that the problem of determining whether a CFG grammar generates any words is decidable. Let

E CFG = { G G是 CFG 语法,L ( G ) = Ø }。

E CFG = { G : G is a CFG grammar and L ( G ) = Ø }.

定理4.8

Theorem 4.8

E CFG是可判定语言。

E CFG is a decidable language.

证明的概念为了找到解决这个问题的算法,我们可以尝试使用定理 4.7 中的 图灵机S。它指出我们可以测试 CFG 语法是否生成中的某个特定单词。为了确定是否L ( G )= Ø ,算法可以顺序尝试所有可能的单词。然而,输入的字数可能是无限的,因此这种方法可能会导致机器无限期地运行。我们需要采取不同的方法。

Concept of Proof To find an algorithm for this problem, we could try to use the Turing machine S of Theorem 4.7. This states that we can test whether the grammar CFG generates some particular word in . To determine whether L ( G ) = Ø , the algorithm could try all possible words in , one by one. However, the number of words in , may be infinite, so this method could cause the machine to run forever. We need to take a different approach.

为了能够确定语法语言是否为空,我们需要检查种子变量是否可以生成仅包含终结符的单词。该算法通过解决更普遍的问题来实现这一点。它为每个变量确定该变量是否能够生成终止词。当算法确定某个变量可以生成某个终结词时,它会通过标记该变量来存储此信息。

In order to determine whether the language of a grammar is empty, we need to check whether the initial variable can generate a word containing only terminals. The algorithm does this by solving a more general problem. It determines for each variable whether that variable is capable of generating a terminal word. Once the algorithm determines that a certain variable can generate a certain terminal word, it records this information by tagging the variable.

首先,该算法标记语法的所有终结符号。然后他回顾了该语法的所有产生。如果它发现一个产生式允许您用某个由已标记符号组成的单词替换某个变量,则意味着该变量也可以被标记。该算法继续以这种方式进行,直到它不再标记任何其他变量。该算法由图灵机R实现。

First, the algorithm labels all terminal symbols of the grammar. Then, it scans all productions of the grammar. If it finds a production that allows replacing a variable with a word consisting of symbols that are already labeled, then that variable can also be labeled. The algorithm continues to do this until it cannot label any more variables. This algorithm is implemented by the Turing machine R .

证据

Evidence

R = "对于输入词G ,其中G是 CFG 语法:

R = "For input word G , where G is a CFG grammar:

  1. 标记G中的所有终端符号。
  2. Label all terminal symbols in G .
  3. 重复以下步骤,直到没有标记新变量:
  4. Repeat the following step until no new variables are tagged:
  5. 标记G包含产生式A U 1 U 2 … · U k的每个变量A,并且每个符号U 1 , …, U k都已标记。
  6. Label each variable A for which G contains the production A U 1 U 2U k and each symbol U 1 , …, U k is already labeled.
  7. 如果起始变量未标记,则接受;否则丢弃。”
  8. If the initial variable is untagged, accept ; otherwise reject ."

我们现在考虑确定两个上下文无关语法是否生成相同语言的问题。让

We now consider the problem of determining whether two context-free grammars generate the same language. Let

EQ CFG = { G , H GH是 CFG 语法且L ( G ) = L ( H )}。

EQ CFG = { G , H : G and H are CFG grammars and L ( G ) = L ( H )}.

定理 4.5 给出了有限自动机的类似EQ DFA语言的解析算法。我们使用E DFA的解析过程来证明EQ DFA是可判定的。由于E CFG也是可判定的,人们可能会认为我们可以使用类似的策略来证明EQ CFG的可判定性。然而,这个想法是有缺陷的!上下文无关语言类既不是由补集封闭,也不是由交集封闭,如练习 2.2 中所示。事实上,EQ CFG语言是不可判定的。证明这一事实的技术将在第五章中介绍。

Theorem 4.5 gives an algorithm for deciding the analogous language EQ DFA for finite automata. There we used the decision procedure for E DFA to prove that EQ DFA is decidable. Since E CFG is also decidable, one might think that we can use an analogous strategy to prove the decidability of EQ CFG . However, this idea contains a flaw! The class of context-free languages ​​is not closed under either complement or intersection, as we showed in Exercise 2.2. In fact, EQ CFG is not decidable. The technique for proving this fact will be presented in Chapter 5.

我们现在可以证明上下文无关语言可以由图灵机判定。

We can now show that context-free languages ​​are decidable by Turing machines.

定理4.9

Theorem 4.9

每种上下文无关语言都是可判定的。

Every context-free language is decidable.

证明的概念 A是一种 CFL 语言。我们的目标是证明A是可判定的。将语言A的 PDA直接转换为图灵机可能是一个(坏)主意。这并不太困难,因为使用图灵机的更灵活的磁带来模拟堆栈很容易。语言A的 PDA可能是非确定性的,但这似乎也很好,因为我们可以将其转换为非确定性机器,并且我们已经知道任何非确定性图灵机都可以转换为等效的确定性机器。然而,困难也来了。一些 PDA 计算路径可以永远运行,读取和写入堆栈并且永不停止。模拟它的图灵机也会有一些无限的计算路径,因此该机器不会是决定性的机器。需要另一个想法。定理4.7中设计的图灵机S来解析A CFG语言来证明这个定理。

Proof Concept Let A be a CFL language. Our goal is to show that A is decidable. One (bad) idea might be to transform the PDA for A directly into a Turing machine. This is not too difficult, since simulating the stack using the more flexible Turing machine tape is easy. The PDA for A might be nondeterministic, but that seems fine too, since we can transform it into a nondeterministic machine, and we already know that any nondeterministic Turing machine can be transformed into its equivalent deterministic machine. But here comes the difficulty. Some paths of computation of the PDA can go on forever, reading and writing the stack and never stopping. The Turing machine simulating it will then also have some infinite paths of computation, and hence this machine will not be a decidable machine. Another idea is needed. We will prove this theorem using the Turing machine S designed in Theorem 4.7 to decide the language A CFG .

证明 G是语言A的 CFG 语法;我们将设计一个图灵机M G来解析A。我们将在MG机器构建语法G的副本。该机器的工作原理如下。

Proof Let G be a CFG grammar for language A ; we design a Turing machine M G that decides A .We build a copy of the grammar G into the machine M G . The machine works as follows.

M G =“对于中的输入词:

M G = "For input word in :

  1. 启动机器S输入单词G , w
  2. Run machine S for input word G , w .
  3. 如果本机接受,则接受;如果拒绝,就拒绝。”
  4. If this machine accepts, accept ; if it rejects, reject ."

定理 4.9 是最后一个元素,它使我们能够确定迄今为止所描述的四种主要语言类别之间的关系:正则语言、上下文无关语言、可判定语言和图灵可识别语言。这些关系如图 4.10 所示。

Theorem 4.9 provides the final piece of information that allows us to derive the correspondences between the four main classes of languages ​​that we have described so far: regular, context-free, decidable, and Turing-decidable languages. These correspondences are illustrated in Figure 4.10.

4.10

语言类之间的关系

Figure 4.10

Relationships between language classes

4.2

不可判定性

4.2

Undecidability

在本节中,我们将证明计算理论中最重要的哲学定理之一。有一个特定的问题在算法上是无法解决的。计算机似乎如此强大,以至于您会认为它们能够解决所有问题。本章提出的定理表明计算机在某些基本方面受到限制。

In this section, we will prove one of the most philosophically important theorems in the theory of computation. There is a particular problem that is algorithmically insoluble. Computers seem so powerful that it would seem that they would be able to solve all problems. The theorem presented in this chapter shows that computers are limited in some fundamental way.

什么样的问题是计算机无法解决的?这些问题是否深奥,只存在于理论家的头脑中?不!即使人们想要解决的一些普通问题也被证明是计算无法解决的。

What kinds of problems are insoluble by computers? Are they esoteric problems that exist only in the minds of theorists? No! Even some ordinary problems that people would like to solve turn out to be computationally insoluble.

在其中一个问题中,我们收到一个计算机程序作为输入,以及该程序应该做什么的精确说明(例如对数字列表进行排序)。您应该检查该程序是否按照规范运行(如果正确)。由于程序和规范都是数学上明确的对象,因此我们可能希望通过将这些对象输入到适当编程的计算机来自动化验证过程。不幸的是,我们会失望的。一般的软件验证问题无法用计算机来解决。

In one such problem, we are given as input a computer program and a precise specification of what the program is to do (e.g., sort a list of numbers). We need to check whether the program complies with the specification (is correct). Since both the program and the specifications are mathematically unique objects, we might hope to automate the verification process by feeding these objects to a suitably programmed computer. Unfortunately, we are disappointed. The general problem of software verification is not solvable by computer.

在本节和第 5 章中,我们将遇到许多计算上无法解决的问题。通过这种方式,我们希望让读者了解哪些类型的问题是无法解决的,并教授证明无法解决的技术。

In this section and in Chapter 5, we will encounter many computationally unsolvable problems. Our goal is to develop in the reader an understanding of the types of problems that are unsolvable and to teach techniques for proving unsolvability.

我们现在转向特定语言的第一个不可判定性定理:确定图灵机是否接受给定输入单词的问题。我们将这种语言称为A TM,与A DFAA CFG类比。然而,虽然A DFAA CFG是可判定的,但A TM却不是。让

We now turn to the first theorem on the undecidability of a particular language: the problem of determining whether a Turing machine accepts a given input word. We will call this language A TM by analogy to A DFA and A CFG . However, while A DFA and A CFG are decidable, A TM is not. Let

A TM = { M , w M是图灵机并且M接受w }。

And TM = { M , w : M is a Turing machine and M accepts w }.

定理4.11

Theorem 4.11

语言A TM是不可判定的。

The language A TM is undecidable.

在继续证明之前,我们可以注意到A TM是图灵可识别的。因此,这个定理表明识别机器比决定机器更强大。要求图灵机对每一个可能的输入都停止,限制了它可以识别的语言集。下面的图灵机U识别ATM语言

Before we proceed to the proof, we may note that A TM is Turing recognizable. Thus, the theorem shows that recognizing machines are more powerful than decisive ones. Requiring a Turing machine to halt for every possible input restricts the set of languages ​​it can recognize. The following Turing machine U recognizes the language A TM .

U = "对于输入单词M , w ,其中M是 TM,w是单词:

U = "For input word M , w , where M is a TM and w is a word:

  1. 模拟M对输入单词的操作。
  2. Simulate the operation of M for input word w .
  3. 如果M进入接受状态,则接受;如果M进入拒绝状态,则拒绝'.
  4. If M ever enters an accepting state, accept ; if M ever enters a rejecting state, reject ."

请注意,如果M循环w ,则该机器会循环输入单词M , w 〉 ,这就是该机器无法解析语言A TM 的原因。如果有某种方法可以告诉M不会针对输入单词w停止,那么算法在这种情况下可能会拒绝。然而,正如我们将看到的,没有算法可以识别这种情况。

Note that this machine loops for input word M , w , if M loops for w , which is why this machine does not resolve the language A TM . If there were some way to determine that M does not halt for input word w , then the algorithm could reject in such a case. However, as we will see, there is no algorithm that can recognize such a situation.

图灵机U本身就很有趣。它是通用图灵机的一个例子,由艾伦·图灵于1936年提出。该机器之所以被称为通用是因为它能够根据其描述来模拟任何其他图灵机。通用图灵机在存储程序计算机的早期设计中发挥了重要作用。

The Turing machine U is interesting in its own right. It is an example of a universal Turing machine , proposed by Alan Turing in 1936. The machine is called universal because it can simulate any other Turing machine from its description. The universal Turing machine played an important role in the early design of stored-program computers.

对角化法

Diagonalization method

不可判定性的证明A TM使用一种称为对角化的技术,由数学家 George Cantor 在 1873 年发明。Cantor 解决了测量无限集大小的问题。如果我们有两个无限集,我们如何判断一个集合是否大于另一个集合,或者它们的大小是否相同?当然,对于有限集这个问题的答案很简单。我们简单地计算有限集的元素,得到的数字就是它的大小。然而,如果我们尝试计算无限集合的元素,我们将永远无法完成!因此,我们不能使用计数方法来确定无限集的相对大小。

The proof of the undecidability of A TM uses a technique called diagonalization, invented by the mathematician Georg Cantor in 1873. Cantor was concerned with the problem of measuring the sizes of infinite sets. Given two infinite sets, how can we tell whether one is larger than the other, or whether they are the same size? Of course, this question is easy to answer for finite sets. We simply count the elements of a finite set, and the number that we get is its size. However, if we try to count the elements of an infinite set, we will never finish! So we cannot use the counting method to determine the relative sizes of infinite sets.

例如,我们采用偶数集合和 { 0 , 1 } 上所有单词的集合。两个集合都是无限的,因此比任何有限集合都大,但是其中一个比另一个大吗?我们如何比较它们的相对大小?

For example, consider the set of even integers and the set of all words over { 0 , 1 }. Both sets are infinite, and therefore larger than any finite set, but is one larger than the other? How could we compare their relative sizes?

康托尔针对这个问题提出了一个相当优雅的解决方案。他注意到,如果一个集合的元素可以分配给另一个集合的元素,则两个有限集合具有相同的大小。此方法无需计数即可比较大小。我们可以将这个想法扩展到无限集。我们将更详细地介绍这一点。

Cantor came up with a rather elegant solution to this problem. He noted that two finite sets have the same size if the elements of one set can be mapped to the elements of the other set. This method compares sizes without resorting to counting. We can extend this idea to infinite sets. Let's state this more precisely.

定义 4.12

Definition 4.12

假设我们有集合A和 B以及A 到B 的函数f 。如果函数f从未将两个不同元素分配到同一点,则称为一对一- 也就是说,如果f ( a ) f ( b ),只要a b。如果 f 耗尽了集合B的所有元素,我们就说f一个“on”函数- 也就是说,如果对于每个b B都存在a A使得f ( a ) = b。如果在“ f : A B ”上存在一个单值函数,我们就说集合A和 B等数的(具有相同的幂)。既一对一又“on”的函数称为互唯一函数。在互唯一函数中,A的每个元素映射到B 的唯一元素,并且对于B的每个元素, A的一个唯一元素映射到B的该元素。互唯一函数只是将集合A的元素与集合B的元素“配对”的一种方式。

Suppose we have sets A and  B and a function f from A to B . A function f is called one-to-one if it never assigns the same point to two different elements – that is, when f ( a ) f ( b ), provided a b . We say that f is a function “onto” if it exhausts all elements of set B – that is, when for every b B there exists a A such that f ( a ) = b . We say that sets A and  B are equinumerous (have the same cardinality) if there exists a one-to-one function “onto” f : A B . A function that is both one-to-one and “onto” is called a one-to-one function . In a one-to-one function, each element of A is mapped to a unique element of B , and each element of B has a corresponding unique element of A mapped to that element of B . A one-to-one function is simply a way of "pairing" the elements of set A with the elements of set B .

这些类型的函数的常见替代术语是单值函数的注入、 “on”函数的满射和互唯一函数的双射。

Common alternative terms for these types of functions are injection for a one-to-one function, surjection for an onto function, and bijection for a one-to-one function.

4.13

Example 4.13

N为自然数集合 {1, 2, 3, …},令E为偶自然数集合 {2, 4, 6, …}。使用康托尔的等价定义,我们可以看到NE 的大小相同。将N映射到E 的双射f就是f ( n ) = 2n。我们可以使用数组更轻松地可视化函数f 。

Let N be the set of natural numbers {1, 2, 3, …} and let E be the set of even natural numbers {2, 4, 6, …}. Using Cantor's definition of equicardinality, we can see that N and E are of the same size. The bijection f from N to E is simply f ( n ) = 2 n . We can more easily visualize the function f using an array.

n

n

f ( n )

f ( n )

1

1

2

2

2

2

4

4

3

3

6

6

这个结果乍一看可能看起来很奇怪。直观上,E看起来比N小,因为E是N的真子集。但是,可以将N中的每个元素与其E中的唯一对应元素配对,因此我们得出结论,两个集合的大小相同。

This result may seem strange at first. Intuitively, E seems smaller than N , since E is a proper subset of N . However, the pairing of each element of N with its exclusive counterpart in E is possible, so we conclude that both sets are the same size.

定义 4.14

Definition 4.14

如果集合 A 是有限的或等价于N,则称该集合A可数的。

A set A is called countable if it is either finite or equinumerous with N .

4.15

Example 4.15

我们现在可以转向一个更奇怪的例子。如果我们定义Q = { m n m , n N },即正有理数集合,那么看起来Q比N大得多。然而,根据我们的定义,这两个集合具有相同的大小。我们将在N上呈现一个互不相同的映射,以表明集合Q是可数的。构建此类函数的一个简单方法是创建Q的所有元素的列表。然后我们将列表的第一个元素指定为N的数字 1,将第二个元素指定为N的数字 2 ,依此类推。我们需要保证每个Q元素仅在此列表中出现一次。

We can now move on to an even stranger example. If we define Q = { m n m , n N }, the set of positive rational numbers, then Q appears to be much larger than N . However, both sets have the same size by our definition. We will provide a one-to-one mapping to N to show that Q is countable. A straightforward way to construct such a function is to create a list of all the elements of Q . Then we assign the first element of the list the number 1 of N , the second element the number 2 of N , and so on. We must guarantee that each element of Q appears in this list only once.

为了获得这个列表,我们创建一个包含所有正有理数的无限矩阵,如图 4.16 所示。第i行包含分子i的所有数字,第 j列包含分母j的所有数字。所以数字i j出现在第 i第 j列。然后我们将这个矩阵转换成一个列表。一个诱人的(但不好的)尝试是从在第一行列出所有项目开始。这不是一个好方法,因为这一行是无限的,因此列表永远不会到达第二行。相反,我们将从角点开始枚举下图中叠加的对角线。第一个对角线包含单个元素D,第二个对角线包含两个元素EA 。所以列表中的前三个元素是DEA 。第三条对角线有一个复杂的情况。它包含FGB。如果我们只是将这些元素添加到列表中,它将包含重复D = G。我们通过省略一个元素来避免这种情况,因为这样做会导致重复。所以我们只添加新元素F和 B。继续这样,我们将获得集合Q的所有元素的列表。

To obtain this list, we create an infinite matrix containing all the positive rational numbers, as in Figure 4.16. The ith row contains all the numbers that have numerator i , and the jth column contains all the numbers that have denominator j . So the number i j appears in the ith row and the jth column. We next transform this matrix into a list. It would be tempting (but bad) to start by enumerating all the elements in the first row. This is not a good approach, because the row is infinite, so the list would never reach the second row. Instead, we enumerate the elements on the diagonals, which are superimposed on the diagram below, starting from a corner. The first diagonal contains a single element D , the second diagonal contains two elements E , and A . So the first three elements in the list are D , E , and A . The third diagonal gets complicated. It contains F , G , and B . If we simply added these elements to the list, it would contain a repetition of D = G . We avoid this by omitting an element when it would cause repetition. So we just add new elements F and  B . Continuing in this way, we get a list of all the elements of Q .

看到NQ的等价性后,人们可能会认为可以证明所有无限集具有相同的大小。最终,我们只需要证明相互的明确性,这个例子表明可能存在令人惊讶的对应关系。然而,对于某些无限集,不存在到N 的相互唯一的映射。这些集合实在是太大了。这样的集合称为不可数

After seeing the equivalence of N and Q , one might think that it would be possible to show that all infinite sets have the same size. After all, we only need to demonstrate mutual uniqueness, and this example shows that there can be surprising correspondences. However, for some infinite sets, there is no mutually unique mapping to N . These sets are simply too large. Such sets are called uncountable .

实数集是不可数集的一个众所周知的例子。实数可以定义为具有小数表示形式的数字,其中小数点后的位数可以是无限的。此类实数的示例有p = 3.1415926… 和2 = 1.4142135… 令R为实数集。康托证明了R是不可数的。在这个证明中他引入了对角化的方法

The set of real numbers is a well-known example of an uncountable set. A real number can be defined as a number with a decimal representation, where the number of digits after the decimal point can be unlimited. Examples of such real numbers are p = 3.1415926… and 2 = 1.4142135… Let R be the set of real numbers. Cantor proved that R is uncountable. In this proof, he introduced the method of diagonalization .

4.16从 NQ

的互唯一映射

Figure 4.16

One-to-one mapping from N to Q

定理4.17

Theorem 4.17

集合R是不可数的。

The set R is uncountable.

证明 为了证明R是不可数的,我们将证明集合NR之间不存在互唯一映射我们将通过产生矛盾来证明这一点。假设有一个互唯一的函数f将N映射到R。我们的任务是证明f不能按其应有的方式工作。为了相互唯一, f必须将N 的所有元素与R的所有元素然而,如果我们发现R中的x与N中的任何元素都不对应,我们就会得到矛盾。

Proof To prove that R is uncountable, we show that there is no one-to-one mapping between sets N and R . We prove it by contradiction. Suppose there is a one-to-one function f that maps N to R . Our task is to show that f cannot work as it should. To be one-to-one, f must pair all elements of N with all elements of R . However, if we find an x ​​from R to which no element from N corresponds , we obtain a contradiction.

我们将使用适当的结构找到这样的x 。我们选择x 的十进制扩展的每个数字,使得x不同于与N的元素配对的后续实数。最后,我们确信x不同于任何已配对的实数。

We find such x using an appropriate construction. We choose each digit of the decimal expansion of x such that x is different from the subsequent real numbers paired with the elements of N . Finally, we are sure that x is different from each real number that has been paired.

我们将通过一个例子来说明这个想法。假设存在互唯一的函数f。设f (1) = 3.14159…、f (2) = 55.55555…、f (3) = …等等,作为一些示例值。换句话说,f将数字 1 映射到 3.14159…,数字 2 映射到 55.55555…,依此类推。下表显示了NR之间假设双射的几个值。

Let us illustrate this idea with an example. Suppose there is a mutually unique function f . Let f (1) = 3.14159…, f (2) = 55.55555…, f (3) = … and so on, as some sample values. In other words, f maps the number 1 to 3.14159…, the number 2 to 55.55555… and so on. The following table shows some values ​​of a hypothetical bijection between N and R .

n

n

f ( n )

f ( n )

1

1

3.14159…

3.14159…

2

2

55.55555…

55.55555…

3

3

0.12345…

0.12345…

4

4

0.50000…

0.50000…

我们将构造我们正在寻找的数字x,并给它一个十进制表示形式。它将是一个介于 0 和 1 之间的数字,因此它的所有有效数字都是小数点后的数字。我们的目标是保证对于任何n , x f ( n ) 。为了确保这一点,我们选择的第一个数字与数字f (1) = 3. 1 4159… 或 1的小数部分的第一个数字不同。令其为数字 4。 保证x f (2),我们选择第二个数字x与第二个数字f (2) = 55.5 5 5555… 不同的任何数字,即 5。让它成为数字 6。第三个小数位f (3) = 0.12 3 45… 是 3,所以让第三个数字x可以是其他任何数字 - 例如,4。继续沿对角线穿过f值数组,我们获得x的所有数字,如下表所示。我们知道对于任何n , x都不等于f ( n ) ,因为它与f ( n ) 在小数点后第 n 位不同。 (您可能会注意到这里有一个小问题,因为某些特定的十进制数,例如 0.1999... 和 0.2000...,即使它们的十进制表示形式不同,也是相等的。我们通过在以下情况下从不选择数字 0 或 9 来避免此问题:构造x。)

We construct the required number x by giving it a decimal representation. It will be a number between 0 and 1, so all its significant digits are the digits after the decimal sign. Our goal is to guarantee that x f ( n ) for any n . To ensure this, we choose the first digit to be something different from the first digit of the fractional part of f (1) = 3. 1 4159…, which is 1. Let this be the digit 4. To ensure that x f (2), we choose the second digit x to be something different from the second digit of f (2) = 55.5 5 5555…, which is 5. Let this be the digit 6. The third fractional digit of f (3) = 0.12 3 45… is 3, so let the third digit of x be something else – for example, 4. Continuing along the diagonal of the table of values ​​of f in this way , we obtain all the digits of x , as shown in the table below. We know that x is not equal to f ( n ) for any n , since it is different from f ( n ) at the nth decimal digit. (You may notice a slight problem here, in that some special decimal numbers, such as 0.1999… and 0.2000…, are equal even though their decimal representations are different. We avoid this problem by never choosing the digits 0 or 9 when constructing x .)

n

n

f ( n )

f ( n )

1

1

3.1 4159

3. 1 4159…

2

2

55.5 5 555…

55.5 5 555…

3

3

0.12 3 45…

0.12 3 45…

x = 0.4641…

x = 0.4641…

4

4

0.500 0 0…

0.500 0 0…

所提出的定理在计算理论中具有重要的应用。它表明有些语言是不可判定的,甚至是图灵可识别的,因为语言有无数种,但图灵机却只有无数种。由于每个图灵机只能识别一种语言,而且语言的数量比图灵机还多,因此有些语言是任何图灵机都无法识别的。此类语言不是图灵可识别的,正如我们在以下结论中得出的结论。

The theorem has significant applications in computational theory. It shows that some languages ​​are not decidable, or even Turing-recognizable, since there are uncountably many languages ​​but only countably many Turing machines. Since each Turing machine recognizes a single language and there are more languages ​​than Turing machines, some languages ​​are not recognized by any Turing machine. Such languages ​​are not Turing-recognizable, as we state in the following corollary.

应用4.18

Motion 4.18

某些语言无法被图灵识别。

Some languages ​​are not Turing recognizable.

证明 为了证明所有图灵机的集合是可数的,我们首先可以注意到对于每个字母表Σ,Σ *中所有单词的集合通过首先列出长度为 0 的所有单词,然后列出长度为 1、2 等的所有单词来构建列表Σ *。

Proof To show that the set of all Turing machines is countable, we can first observe that for any alphabet Σ, the set of all words in Σ * is countable. Given only a finite number of words of a given length, we can construct the list Σ * by first writing out all words of length 0, then all words of length 1, 2, and so on.

所有图灵机的集合是可数的,因为每个M机器都被编码为一个单词M 。如果我们简单地省略未正确编码的图灵机的单词,我们将获得所有图灵机的列表。

The set of all Turing machines is countable, since each machine M corresponds to an encoding as a word M . If we simply omitted those words that are not well-coded Turing machines, we would obtain a list of all Turing machines.

为了证明所有语言的集合是不可数的,我们首先可以注意到所有无限二进制序列的集合是不可数的。无限二进制序列是由 0 和 1 组成的无限序列。设B为所有无限二元序列的集合。我们可以通过对角化证明来证明B不可数,类似于定理4.17证明R不可数的方法。

To show that the set of all languages ​​is uncountable, we can first observe that the set of all infinite binary sequences is uncountable. An infinite binary sequence is an infinite sequence of zeros and ones. Let B be the set of all infinite binary sequences. We can prove that B is uncountable using a proof by diagonalization, analogous to the method used in the proof of Theorem 4.17 to show that R is uncountable.

L为字母表Σ上所有语言的集合。我们将通过给出该集合到B的互唯一映射来证明L是不可数的,从而证明这些集合是等数的。设Σ * = { s 1 , s 2 , s 3 , …}。对于每种语言A L,B中都有一个唯一的序列。它的工作原理是这样的:如果s iA,则该序列的第 i位元素为 1,如果s iA,第 i位为 0;这样的序列称为特征序列A。例如,如果A是字母表 { 0 , 1 } 中所有以0开头的单词的语言,则其特征序列χ A将具有以下形式:

Let L be the set of all languages ​​over the alphabet Σ . We show that L is uncountable by giving a one-to-one mapping from this set to B , and thus by showing that these sets are equinumerous. Let Σ * = { s 1 , s 2 , s 3 , …}. For each language A L there is a unique sequence in B . This works in such a way that if s i A then the i -th element of this sequence is 1, and if s i A then the i -th bit is 0; such a sequence is called the characteristic sequence of A . For example, if A is the language of all words starting with 0 over the alphabet { 0 , 1 }, its characteristic sequence χ A will have the following form:

Σ * = { ε, 0, 1, 00, 01, 10, 11, 000, 001, …} ;

Σ * = { ε, 0, 1, 00, 01, 10, 11, 000, 001, …} ;

A = { 0, 00, 01, 000, 001, …} ;

A = { 0, 00, 01, 000, 001, …} ;

χ A = 0 1 0 1 1 0 0 1 1 ….

χA = 0 1 0 1 1 0 0 1 1 ….

函数f : L B,其中f ( A ) 是语言A的特征序列,是一对一且“on”的,因此是相互唯一的。因此,如果B不可数,则L也不可数。

The function f : L B , where f ( A ) is the characteristic sequence of the language A , is one-to-one and onto, and therefore mutually unique. Therefore, since B is uncountable, L is also uncountable.

因此,我们证明不可能在所有语言的集合和所有图灵机的集合之间创建相互唯一的映射。这意味着某些语言无法被任何图灵机识别。

We have thus shown that it is impossible to have a one-to-one mapping between the set of all languages ​​and the set of all Turing machines. It follows that some languages ​​are not recognized by any Turing machine.

不可判定的语言

Undecidable language

现在我们可以继续证明关于语言不可判定性的定理 4.11

We can now proceed to prove Theorem 4.11 on the undecidability of the language

A TM = { M , w M是图灵机,M接受单词w }。

A TM = { M , w : M is a Turing machine and M accepts a word w }.

证明 我们假设语言A TM是可判定的,并导致矛盾。假设H是A TM的决策机。对于输入单词M , w ,其中M是图灵机, w是单词,如果M接受单词w ,则H停止并接受。此外,如果M不接受中的单词, H就会停止并拒绝。换句话说,我们假设H是图灵机,其中

Proof We will assume that the language A TM is decidable, and we will reach a contradiction. Suppose H is a decidable machine for A TM . For an input wordM , w , where M is a Turing machine and w is a word, H halts and accepts if M accepts the word w . Moreover, H halts and rejects if M does not accept the word w . In other words, we assume that H is such a Turing machine, where

1

我们现在将构造一个新的图灵机D,其中包含H作为子程序。这个新机器调用H来计算当M的输入是它自己的描述M 〉时机器M将做什么。当D获得此信息时,它执行相反的操作,即如果M接受则拒绝,如果M不接受则接受。下面是机器D的描述。

We now construct a new Turing machine D containing H as a subroutine. This new machine calls H to compute what M will do when M is given its own description M as input . Once D has this information, it does the inverse, rejecting if M accepts, and accepting if M does not accept. The following is a description of D .

D = "对于输入词M ,其中M是图灵机:

D = "For input word M , where M is a Turing machine:

  1. 对输入单词M , M 〉〉运行H
  2. Run H for input word M , M 〉〉 .
  3. 返回H的相反结果。因此,如果H接受,则拒绝,如果H拒绝,则接受
  4. Return the inverse of H . That is, if H accepts, reject , and if H rejects, accept ”.

不要对在其自己的描述中提到运行机器感到惊讶!这类似于以自身(此程序)作为输入来运行程序,这在实践中有时会发生。例如,编译器是翻译其他程序的程序。 Python 编译器本身可以用 Python 编写,因此在其自身上运行该程序可能是有意义的。总结,

Don't be surprised to hear about running the machine on its own description! This is similar to running a program with itself (the program) as input, something that sometimes happens in practice. For example, a compiler is a program that translates other programs. A Python compiler can itself be written in Python, so running this program "on itself" can make sense. To summarize,

1

但是如果我们使用 D 自己的描述D 作为输入来运行D会发生什么?在这种情况下我们会得到

But what happens if we run D with its own description D as input? In that case we get

1

无论D做什么,他都被迫做相反的事情,这是一个明显的矛盾。因此机器D和机器H都不可能存在。

No matter what D does , it is forced to do the opposite, which is an obvious contradiction. Therefore, neither machine D nor machine H can exist.

让我们看看这个证明的各个步骤。我们假设机器H解析语言ATM。我们使用H构建一台接受M 作为输入的机器D,当M不接受其输入M 时,D接受其输入M 。最后,我们使用我们自己的描述作为输入来运行D。所以机器会执行以下操作,最后一行是矛盾的。

Let's look at the individual steps of this proof. We assume that a machine H resolves a language A TM . We use H to construct a machine D that takes M as input , where D accepts its input M exactly when M does not accept its input M . Finally, we run D with its own description given as input. So the machines do the following, with the last line being a contradiction.

  • 当M接受w时, H恰好接受M , w
  • H accepts M , w exactly if M accepts w .
  • M接受〈M〉D拒绝〈M〉
  • D rejects M , while M accepts M .
  • D接受〈D〉D拒绝〈D〉
  • D rejects D , while D accepts D .

定理4.11的证明中哪里可以找到对角化呢?当我们检查图灵机HD的行为表时,这一点就会变得显而易见。在这些表中,我们在行中列出了所有图灵机M 1M 2、...,在列中列出了它们的描述M 1 M 2 、 ... 这些条目告诉机器是否以给定行接受来自特定列的输入。如果机器接受输入,则该条目为接受;如果机器拒绝或循环该输入,则该条目为空白。我们在下面的示例中说明了这个想法,显示了几个表条目。

Where do we find diagonalization in the proof of Theorem 4.11? This becomes obvious when we examine the behavior tables of Turing machines H and D . In these tables, we list in rows all the Turing machines M 1 , M 2 , …, and their descriptions in columns, M 1 , M 2 , …. These entries tell us whether the machine represented in a given row accepts the input from a given column. The entry is accept if the machine accepts the given input, or a blank if the machine rejects or loops for that input. We illustrate this idea in the following example, showing several entries in the table.

4.19如果M i接受M j〉,则单元格i , j

中的条目被接受

Figure 4.19

Entry in cell i , j then accept if M i accepts M j

在下图中,条目是对图 4.19 对应的输入运行H的结果。因此,如果M 3不接受输入< M 2 > ,则M 3行和< M 2 >列中的条目将被拒绝,因为H拒绝输入< M 3< M 2 >>

In the next figure, the entries are the results of running H for the inputs corresponding to Figure 4.19. Thus, if M 3 does not accept the input M 2 , then the entry in row M 3 and column M 2 is reject , since H rejects the input M 3 , M 2 〉〉 .

4.20

单元格i , j中的条目是输入单词M 3 , M 2 〉〉H的返回值

Figure 4.20

The entry in cell i , j is the value returned by H for the input word M 3 , M 2 〉〉

在下图中,我们将机器D添加到图 4.20 中的数组中。根据假设,H是图灵机,因此D也是机器。因此,它必须出现在所有图灵机的列表M 1 , M 2 , ... 中。请注意, D计算的结果与对角线上的条目相反。矛盾出现在标有问号的地方,其中的条目必须与自身相反。

In the next figure, we have added a machine D to the table in Figure 4.20 . By assumption, H is a Turing machine, and so is D. Therefore, it must appear in the list M 1 , M 2 , … of all Turing machines. Notice that the results of computing D are the inverses of the entries on the diagonal. The contradiction occurs at the point marked with a question mark, where the entry must be the inverse of itself.

4.21

若图中为D ,则在标有“?”的位置处存在矛盾

Figure 4.21

If D is in the figure, then there is a contradiction at the place marked "?"

图灵无法识别的语言

Turing-unrecognizable language

在上一节中,我们介绍了一种不可判定的语言,特别是A TM。我们现在将展示一种在图灵意义上甚至无法识别的语言。请注意,语言A TM不足以实现此目的,因为我们已经证明它是图灵可识别的(第 202 页)。以下定理表明,如果一种语言及其补语都是图灵可识别的,则该语言是可判定的。由此可见,对于任何不可判定的语言,它或其补语都不是图灵可识别的。回想一下,语言的补语是由所有不属于原始语言的单词组成的语言。如果一种语言的补语是图灵可识别的语言,我们就说它是图灵可识别的。

In the previous section, we presented a language—specifically, A TM —that is undecidable. We will now show a language that is not even Turing-recognizable. Note that for this purpose, A TM is not enough, since we have shown that it is Turing-recognizable (page 202). The following theorem shows that if both a language and its complement are Turing-recognizable, then the language is decidable. It follows that for any undecidable language, either it or its complement is not Turing-recognizable. Recall that the complement of a language is the language consisting of all the words that do not belong to the original language. We say that a language is Turing - co -recognizable if its complement is a Turing-recognizable language.

定理4.22

Theorem 4.22

一种语言是可判定的当且仅当它是图灵可识别的并且在图灵意义上是可共同识别的。

A language is decidable if and only if it is Turing recognizable and Turing co-recognizable .

换句话说,当且仅当一种语言及其补语是图灵可识别的时,它才是可判定的。

In other words, a language is decidable if and only if it and its complement are Turing-decidable.

证明 我们有两个方向的含义需要证明。首先,如果A是可判定语言,那么我们很容易看出A及其补集A都是图灵可破译的。每个可判定语言都是图灵可判定的,并且可判定语言的补集也是可判定的。

Proof We have two directions of implication to prove. First, if A is a decidable language, then we can easily see that both A and its complement A are Turing recognizable. Every decidable language is Turing recognizable, and the complement of a decidable language is also decidable.

对于相反的蕴涵方向,如果A和 A是图灵可识别的,则令M 1为识别A的机器,M 2为识别A的机器。下面的图灵机MA的决胜机。

For the opposite direction of implication, if A and  A are Turing-recognizable, let M 1 be a machine recognizing A , and M 2 be a machine recognizing A . The following Turing machine M is a deciding machine for A .

M =“对于中的输入词:

M = "For input word in :

  1. 针对输入字w并行运行两台机器M 1M 2
  2. Run both machines M 1 and M 2 in parallel for input word w .
  3. 如果机器M 1接受,则接受;如果机器M 2接受,则拒绝。”
  4. If machine M 1 accepts, accept ; if machine M 2 accepts, reject ".

并行运行两台机器意味着M有两盘磁带,一盘模拟机器M 1,另一盘模拟M 2。在这种情况下,M交替模拟每台机器的一个步骤,一直持续到其中一台机器接受其输入为止。

Running two machines in parallel means that M has two tapes, one to simulate machine M 1 and the other to simulate M 2 . In this case, M alternately simulates one step of each machine, continuing until one of them accepts its input.

我们现在将证明机器M解析A。中的每个单词属于AA。因此机器M 1M 2之一必须接受w。由于当M 1M 2接受时M停止,因此M将始终停止,因此是决胜局机器。此外,它接受所有属于A 的单词拒绝所有不属于A 的单词。因此M是语言A的判定器机器,因此A是可判定的。

We now show that a machine M decides A . Each word w belongs either to A or to A . Hence one of the machines M 1 or M 2 must accept w . Since M halts whenever M 1 or M 2 accepts, M will always halt and is hence a decider. Moreover, it accepts all words belonging to A and rejects all that do not belong to A . Hence M is a decider for the language A , and hence A is decidable.

结论4.23

Motion 4.23

A TM语言不是图灵可识别的。

The A TM language is not Turing-recognizable.

证明 我们知道A TM是图灵可识别的。如果A TM也是图灵可解析的,那么A TM将是一种可判定的语言。从定理 4.11 可以看出, A TM不是可判定的语言,因此A TM不能是图灵可破译的。

Proof We know that A TM is Turing recognizable. If A TM were also Turing recognizable, then A TM would be a decidable language. It follows from Theorem 4.11 that A TM is not a decidable language, so A TM cannot be Turing recognizable.

练习

Exercises

A 4.1回答下面所示的 DFA M 的所有项目并提供答案的理由。

A 4.1 Answer each question for the DFA M shown below and justify your answer.

a.M , 0100 A DFA吗?

a. Is M , 0100 A DFA ?

b. M , 011 A DFA 吗?

b. Is M , 011 A DFA ?

c . 〈M〉 是否A DFA

c. Is M A DFA ?

d.< M , 0100 > A REX吗?

d. Is M , 0100 A REX ?

e . 〈M〉 是否E DFA

e. Is M E DFA ?

f . M , M 是否EQ DFA

f. Does M , M EQ DFA ?

4.2 考虑判断某个DFA和某个正则表达式是否等价的问题。将这个问题表述为一种语言并证明它是可判定的。

4.2 Consider the problem of determining whether a certain DFA and a certain regular expression are equivalent. State this problem as a language and show that it is decidable.

4.3ALL DFA = { A A是 DFA 并且L ( A ) = Σ * }。证明所有DFA都是可判定的。

4.3 Let ALL DFA = { A : A is a DFA and L ( A ) = Σ * }. Prove that ALL DFA is decidable.

4.4CFG = { G G是生成 ε} 的 CFG 文法。证明CFG是可判定的。

4.4 Let CFG = { G : G be a CFG generating ε}. Prove that CFG is decidable.

A 4.5E TM = {M M是图灵机且L ( M ) = Ø }。证明E TM是E TM的补集,是图灵可识别的。

A 4.5 Let E TM = {M : M is a Turing machine and L ( M ) = Ø }. Show that E TM , the complement of E TM , is Turing recognizable.

4.6X为集合 {1, 2, 3, 4, 5},Y为集合 {6, 7, 8, 9, 10}。下表描述了函数f : X Yg : X Y。回答每个问题并提供否定答案的理由。

4.6 Let X be the set {1, 2, 3, 4, 5} and Y be the set {6, 7, 8, 9, 10}. The following tables describe the functions f : X Y and g : X Y . Answer each question and justify negative answers.

n

n

f ( n )

f ( n )

n

n

f ( n )

f ( n )

1

1

6

6

1

1

10

10

2

2

7

7

2

2

9

9

3

3

6

6

3

3

8

8

4

4

7

7

4

4

7

7

5

5

6

6

5

5

6

6

a a. f是一对一的 吗

And a. Is f one-to-one?

b. f是“na” 吗?

b. Is f "on"?

c. f互不相同 吗?

c. Is f one-to-one?

A d. g是一对一的 吗

And d. Is g one-to-one?

e. g是“na” 吗?

e. Is g "on"?

f. g互不相同 吗?

f. Is g one-to-one?

4.7B为字母表 {0,1} 上所有无限单词的集合。使用对角化证明证明B不可数。

4.7 Let B be the set of all infinite words over the alphabet {0,1}. Prove that B is uncountable using proof by diagonalization.

4.8T = {( i , j , k ) : i , j , k N }。证明T是可数的。

4.8 Let T = {( i , j , k ) : i , j , k N }. Prove that T is countable.

4.9 回到定义 4.12(第 203 页)中我们如何定义集合等价性。证明“等价”是等价关系。

4.9 Return to the definition of equicardinality of sets in Definition 4.12 (page 203). Show that “equivalence” is an equivalence relation.

任务

Tasks

A 4.10INFINITE DFA = { <A> A是DFA, L ( A )是无限语言}证明INFINITE DFA是可判定语言。

A 4.10 Let INFINITE DFA = {A : A is a DFA and L ( A ) is an infinite language}. Prove that INFINITE DFA is a decidable language.

4.11INFINITE PDA = { M M是 PDA,L ( M ) 是无限语言}。证明INFINITE PDA是可判定的。

4.11 Let INFINITE PDA = { M : M is a PDA and L ( M ) is an infinite language}. Prove that INFINITE PDA is decidable.

A 4.12A = {M M是一个 DFA,不接受任何包含奇数个 1 的单词}。证明A是可判定的。

A 4.12 Let A = {M : M be a DFA that does not accept any word containing an odd number of ones}. Prove that A is decidable.

4.13A = { R , S RS是正则表达式,且L ( R ) L ( S )}。证明A是可判定的。

4.13 Let A = { R , S : R and S are regular expressions and L ( R ) L ( S )}. Prove that A is decidable.

4.14Σ = {0,1}。证明判断某个CFG文法是否生成某个属于1 *的单词的问题是可判定的。换句话说,表明

A 4.14 Let Σ = {0,1}. Show that the problem of determining whether a certain CFG generates a certain word belonging to 1 * is decidable. In other words, show that

{ G : G是字母表 {0,1} 上的 CFG 文法,并且 1 * L ( G ) Ø }

{ G : G is a CFG grammar over the alphabet {0,1} and 1 * L ( G ) Ø }

是可判定语言。

is a decidable language.

*4.15证明确定某个CFG文法是否生成属于1 * 的所有单词的问题是可判定的。换句话说,证明 { G : G是字母表 {0,1} 上的 CFG 文法,并且 1 * L ( G ) } 是可判定语言。

*4.15 Prove that the problem of determining whether a certain CFG grammar generates all words belonging to 1 * is decidable. In other words, show that { G : G is a CFG grammar over the alphabet {0,1} and 1 * L ( G ) } is a decidable language.

4.16 设 A = { <R>R是描述一种语言的正则表达式,该语言包含至少一个包含子词 111 的单词,对于某些xy w = x 111 y)}。证明A是可判定的。

4.16 Let A = { R : R is a regular expression describing a language containing at least one word that contains a subword 111 (that is, w = x 111 y for some x and y )}. Prove that A is decidable.

4.17通过创建一个算法来比较两个 DFA 对于给定长度内所有单词的性能, 证明EQ DFA是可判定的。计算足够的长度。

4.17 Prove that EQ DFA is decidable by constructing an algorithm that compares the performance of two DFAs for all words up to a specified length. Compute a length that will be sufficient.

*4.18C是一种语言。证明C是图灵可译的当且仅当存在可判定语言D使得C = { x : y ( x , y D )}。

*4.18 Let C be a language. Prove that C is Turing recognizable if and only if there is a decidable language D such that C = { x : y ( x , y D )}.

*4.19 证明可判定语言的类不是由于同态而封闭的。

*4.19 Prove that the class of decidable languages ​​is not closed under homomorphism.

4.20A和 B是两种不相交的语言。如果A CB C,我们说语言C将 A和 B分开 。证明任何两个不相交的共图灵语言都可以被某种可判定的语言分开。

4.20 Let A and  B be two disjoint languages. We say that a language C separates A and  B if A C and B C . Prove that any two disjoint Turing-recognizable languages ​​can be separated by some decidable language.

4.21S = { M M是一个 DFA,只要它在 } 中接受,它就R中接受。证明S是可判定的。

4.21 Let S = { M : M is a DFA accepting in R whenever it accepts in }. Prove that S is decidable.

4.22PREFIX-FREE REX = { R R是正则表达式,L ( R ) 是前缀语言}。证明PREFIX-FREE REX是可判定的。为什么类似的方法不能证明PREFIX-FREE CFG是可判定的?

4.22 Let PREFIX-FREE REX = { R : R is a regular expression and L ( R ) is a prefix language}. Show that PREFIX-FREE REX is decidable. Why can't a similar approach show that PREFIX-FREE CFG is decidable?

A* 4.23 如果 NFA 在两个不同的计算路径中接受某个单词,我们就说它是有歧义的。设AMBIG NFA = {N N是一个不明确的 NFA}。证明AMBIG NFA语言是可判定的。 (建议:解决此问题的一个优雅方法是构造一个适当的 DFA,然后为其运行E DFA)。

A* 4.23 We say that an NFA is ambiguous if it accepts a certain word on two different computation paths. Let AMBIG NFA = {N : N is an ambiguous NFA}. Show that the language AMBIG NFA is decidable. (Suggestion: An elegant way to solve this problem is to construct a suitable DFA and then run E DFA on it .)

4.24 堆栈机中的无用状态是指任何输入字都不会达到的状态。考虑确定堆叠自动机是否具有任意垃圾状态的问题。将这个问题表述为一种语言并证明它是可判定的。

4.24 A useless state in a pushdown automaton is one that is never reached for any input word. Consider the problem of determining whether the pushdown automaton has any useless states. Formulate this problem as a language and show that it is decidable.

A* 4.25BAL DFA = {M M是一个 DFA,它接受某个包含相同数量的 0 和 1 的单词}。证明BAL DFA可判定。 (提示:关于上下文无关语言的定理在这里会有帮助。)

A* 4.25 Let BAL DFA = {M : M is a DFA that accepts some word containing an equal number of zeros and ones}. Show that BAL DFA is decidable. (Hint: The theorems about context-free languages ​​are helpful here.)

*4.26PAL DFA = { M M是接受某个回文的 DFA}。证明PAL DFA是可判定的。 (提示:有关上下文无关语言的定理将会有所帮助。)

*4.26 Let PAL DFA = { M : M is a DFA that accepts some palindrome}. Show that PAL DFA is decidable. (Hint: The theorems about context-free languages ​​will be helpful.)

*4.27E = { M | M是一个DFA,接受某个单词包含的1多于0}。证明E是可判定的。 (提示:关于上下文无关语言的定理在这里会有帮助。)

*4.27 Let E = { M | M be a DFA accepting some word with more ones than zeros}. Show that E is decidable. (Hint: Theorems about context-free languages ​​are helpful here.)

4.28C = { G , x G是 CFG 文法,x是某个单词y L ( G )}的子词。证明C是可判定的。 (提示:这个问题的一个优雅的解决方案是使用E CFG解析机。)

4.28 Let C = { G , x : G is a CFG and x is a substring of some word y L ( G )}. Show that C is decidable. (Hint: An elegant solution to this problem uses the decidable machine for E CFG .)

4.29C CFG = { G , k G是一个 CFG 语法,L ( G ) 恰好包含k 个单词,k ≥ 0 或¥ }。证明C CFG是可判定的。

4.29 Let C CFG = { G , k : G is a CFG grammar and L ( G ) contains exactly k words, k ≥ 0 or ¥ }. Prove that C CFG is decidable.

4.30A是一种图灵可识别的语言,由图灵机的描述组成,{ M 1 , M 2 , …},其中每个M i是一个解析器机器。证明某些可判定语言D不能被A中描述的任何机器M i判定。 (提示:考虑A 的枚举器可能会有所帮助。 )

4.30 Let A be a Turing-recognizable language composed of Turing machine descriptions, { M 1 , M 2 , …}, where each M i is a decidable machine. Prove that some decidable language D is not decidable by any of the machines M i whose descriptions appear in A . (Hint: It may be helpful to consider an enumerator for A .)

4.31如果属于 CFG 语法G的 变量A出现ε L ( G )中某个单词的某些推导中,我们就说它是可用的。给定一个 CFG 语法G和一个变量A ,考虑检查A是否可用的问题。将这个问题表述为一种语言并证明它是可判定的。

4.31 A variable A belonging to a CFG grammar G is said to be usable if it occurs in some derivation of some word w L ( G ). Given a CFG grammar G and a variable A , consider the problem of testing whether A is usable. Formulate this problem in terms of a language and show that it is decidable.

4.32 在引理 2.41 的证明中,我们定义 ( q , x ) 是一个DPDA 循环情况P,如果P运行在状态q且符号x Γ在堆栈顶部,则永远不会从堆栈中弹出x下面的任何内容,也不会读取输入符号。证明语言F是可判定的,其中F = { P , q , x : ( q , x ) 是自动机P }的循环。

4.32 In the proof of Lemma 2.41 we defined that ( q , x ) is a looping situation of a DPDA P if P started in state q with symbol x Γ at the top of the stack will never pop anything below x and will never read an input symbol. Show that the language F is decidable, where F = { P , q , x : ( q , x ) is a looping situation of P }.

精选解决方案

Selected solutions

4.1(a) 是的。 DFA M接受 0100。

4.1 (a) Yes. DFA M accepts 0100.

(b) 没有。M不接受011。

(b) No. M does not accept 011.

(c) 没有。该输入只有一个组成部分,因此形式不正确。

(c) No. This input has only one component and is therefore not in a valid form.

(d) 没有。第一个组件不是正则表达式,因此输入无效。

(d) No. The first component is not a regular expression, so the input is not valid.

(e) 没有。M语言不是空的。

(e) No. The language M is not empty.

(f) 是的。M接受与自己相同的语言。

(f) Yes. M accepts the same language as himself.

4.5s 1 , s 2 , … 为属于Σ *的所有单词的列表。以下图灵机识别E TM

4.5 Let s 1 , s 2 , … be a list of all words belonging to Σ * . The following Turing machine recognizes E TM .

对于输入词<M>

"For input word M ,:

1. 检查M是否是图灵机的描述并接受。

1. Check if M is a description of a Turing machine and accept.

2.对于i = 1, 2, 3, … 重复以下步骤

2. Repeat the following steps for i = 1, 2, 3, …

3.对每个输入s 1 , s 2 , …, s i 执行Mi 个步骤。

3. Execute M for i steps for each of the inputs s 1 , s 2 , …, s i .

4. 如果M接受了这些词中的任何一个,则接受。否则,继续。”

4. If M has accepted any of these words, accept . Otherwise continue."

4.6 ( a ) 不,f不是一对一的,因为f (1) = f (3)。

4.6 ( a ) No, f is not one-to-one, since f (1) = f (3).

( d ) 是的,g是一值的。

( d ) Yes, g is one-to-one.

4.10下面的图灵一号 机器解析了INFINITE DFA语言。

4.10 The following Turing machine I decides the INFINITE DFA language .

I = "对于输入词A ,其中A是 DFA:

I = "For input word A , where A is a DFA:

1.k为A的状态数。

1. Let k be the number of states of A .

2.构造一个接受所有长度为k及以上的单词的 DFA D。

2. Construct a DFA D that accepts all words of length k and greater.

3. 构造 DFA M使得L ( M ) = L ( A ) L ( D )。

3. Construct a DFA M such that L ( M ) = L ( A ) L ( D ).

4.使用图灵机T从定理 4.4解析E DFA , 检查L ( M ) = Ø 。

4. Check that L ( M ) = Ø , using the Turing machine T deciding E DFA by Theorem 4.4.

5. 如果T接受,则拒绝;如果T拒绝,则接受

5. If T accepts, reject ; if T rejects, accept ."

该算法之所以有效,是因为对于接受无限多个单词的 DFA,接受单词的长度没有上限。因此,该算法将接受这样的 DFA 自动机。相反,如果算法接受某个 DFA,则自动机接受长度为k或更大的某些字,其中k是该 DFA 的状态数。这个词可以根据正则语言的泵浦引理进行泵浦,以获得无限多个接受的单词。

This algorithm works because for a DFA that accepts infinitely many words, there is no upper bound on the length of the accepted word. Therefore, the algorithm will accept such a DFA. Conversely, if the algorithm accepts a certain DFA, the DFA accepts some words of length k or more, where k is the number of states of the DFA. This word can be pumped in a way that follows from the pumping lemma for regular languages ​​to obtain infinitely many accepted words.

4.12 下面所示的图灵机解析语言A。

4.12 The Turing machine shown below resolves the language A .

“对于输入<M>

"For input word M :

1.构造一个接受任何包含奇数个 1 的单词的 DFA O。

1. Construct a DFA O that accepts any word containing an odd number of 1s.

2. 构造 DFA B使得L ( B ) = L ( M ) L ( O )。

2. Construct a DFA B such that L ( B ) = L ( M ) L ( O ).

3.使用T机解析定理 4.4 中的E DFA语言 ,检查L ( B ) = Ø 。

3. Check that L ( B ) = Ø , using the machine T that resolves the DFA language E by Theorem 4.4.

4. 如果T接受,则接受;如果T拒绝,则拒绝'.

4. If T accepts, accept ; if T rejects, reject ."

4.14 在问题 2.18 中,我们证明如果C是上下文无关语言且R是正则语言,则C R是上下文无关语言。由此可见 1 * L ( G ) 是一种上下文无关语言。下面的图灵机解决了这个问题的语言。

4.14 In Problem 2.18 we showed that if C is a context-free language and R is a regular language, then C R is a context-free language. It follows that 1 * L ( G ) is a context-free language. The following Turing machine solves the language problem.

“对于输入〈G〉

"For input word G :

1. 构造一个 CFG 语法H,使得L ( H ) = 1 * L ( G )。

1. Construct a CFG grammar H such that L ( H ) = 1 * L ( G ).

2.使用R机器解析定理 4.8 中的E CFG语言 ,检查L ( H ) = Ø 。

2. Check that L ( H ) = Ø , using the machine R resolving the language E CFG by Theorem 4.8.

3. 如果R接受,则拒绝;如果R拒绝,则接受

3. If R accepts, reject ; if R rejects, accept ."

4.23 以下过程解析AMBIG NFA语言。给定一个 NFA N,我们设计一个 DFA D来模拟N并接受一个单词当且仅当它在两个不同的计算路径中被N接受时。然后我们使用E DFA的解析器来确定D是否接受任何单词。

4.23 The following procedure resolves an AMBIG NFA language . Given an NFA N , we design a DFA D that simulates N and accepts a word if and only if it is accepted by N on two different paths of computation. We then use the arbitration machine for the E DFA to determine whether D accepts any words.

构建D的策略类似于定理 1.39 证明中提出的 NFA 到 DFA 的转换。我们通过在每个活动状态下放置彩色鹅卵石来模拟N的动作。我们首先在初始状态和从初始状态通过 ε 转换可到达的每个状态中放置一个红色卵石。然后,通过动作,根据机器N的通道添加和移除卵石,控制卵石的颜色。每当两个或多个鹅卵石移动到同一状态时,我们就会用蓝色鹅卵石替换其鹅卵石。读取输入单词后,如果在接受状态N中有蓝色卵石,或者两个不同的接受状态有红色卵石,我们就接受。

The strategy for constructing D is similar to the conversion of NFA to DFA presented in the proof of Theorem 1.39. We simulate the action N , placing colored pebbles in each active state. We start with a red pebble in the initial state and in each state reachable from the initial state by ε-transitions. Then, making moves, we add and remove pebbles according to the transitions of N , controlling the colors of the pebbles. Whenever two or more pebbles are moved to the same state, we replace its pebbles with a blue pebble. After we finish reading the input word, we accept if the accepting state N contains a blue pebble or if two different accepting states have red pebbles.

DFA D具有与每种可能的卵石排列相对应的状态。对于每个状态N都有三种可能性:它可能包含红色卵石、蓝色卵石或两者都不包含。因此,如果N包含n 个状态,则D将有 3n 个状态。适当地定义其初始状态、接受状态和转换函数以执行所描述的模拟。

The DFA D has states corresponding to every possible arrangement of pebbles. For each state N , there are three possibilities: it can contain a red pebble, a blue pebble, or neither. Thus, if N contains n states, then D will have 3n states . Its initial state, accepting states, and transition function are defined appropriately to perform the simulation described.

4.25 所有具有相同数量的 0 和 1 的单词的语言是上下文无关语言,由语法S 1 S 0 S |生成。 01| ε。令P为识别该语言的堆栈自动机。我们将为BAL DFA构建一个图灵机M,工作原理如下。对于输入词B ,其中B是 DFA,我们将使用BP构造一个新的 PDA R来识别语言BP的交集。然后我们将检查R是否为空。如果为空,则丢弃;否则接受

4.25 The language of all words with equal numbers of zeros and ones is a context-free language, generated by the grammar S 1 S 0 S | 0 S 1 S | ε. Let P be a pushdown automaton recognizing this language. We construct a Turing machine M for the BAL DFA , operating as follows. For an input word B , where B is a DFA, we use B and P to construct a new PDA R recognizing the intersection of languages ​​B and P . We then check whether the language R is empty. If it is empty, reject ; otherwise accept .

5

还原性

5

Reducibility

在第四章中,我们选择图灵机作为通用计算机的模型。我们提供了许多可以使用图灵机解决的问题的示例,以及计算无法解决的问题(A TM)的示例。在本章中,我们将了解一些其他无法解决的问题。在这些考虑的过程中,我们将提出一种证明问题在计算上无法解决的基本方法,称为归约

In Chapter 4, we chose the Turing machine as a model for a general-purpose computer. We presented several examples of problems that are solvable using a Turing machine, as well as an example of a computationally insolvable problem ( A TM ). In this chapter, we will consider several additional unsolvable problems. In the process, we will introduce a basic method for proving that a problem is computationally insolvable, called reduction .

归约是一种将一个问题转化为另一个问题的方法,以便第二个问题的解决方案可以用来解决第一个问题。这种减少在日常生活中经常发生,尽管我们通常不这样称呼它们。

Reduction is a method of transforming one problem into another in such a way that the solution to the second problem can be used to solve the first. Such reductions occur frequently in everyday life, although we usually do not call them that.

例如,假设我们需要在一个新的、未知的城市中找到出路。我们知道,如果我们有地图的话,一切都会很容易。因此,我们可以将寻找穿过城市的路线的问题简化为获取该城市的地图的问题。

For example, suppose we need to find our way through a new, unfamiliar city. We know that this would be easy if we had a map. So we can reduce the problem of finding our way through the city to the problem of getting a map of that city.

可归约性总是涉及两个问题,我们可以称之为A和 B。如果A简化为B ,那么我们可以使用B的解来求解A。在我们的示例中,A是在未知城市中找路的问题,B是获取地图的问题。请注意,可归约性并未提及问题AB本身的解决方案,而仅涉及当问题B的解决方案已知时如何解决问题A。

Reducibility always concerns two problems, which we can call A and  B . If A reduces to B , then we can use the solution to B to solve A . In our example, A is the problem of finding our way around an unknown city, and B is the problem of obtaining a map. Note that reducibility tells us nothing about the solutions to problems A or B themselves , only how to solve problem A when the solution to problem B is known .

以下是可还原性的一些其他示例。从波士顿到巴黎的旅行问题简化为购买这些城市之间航班的机票的问题。这个问题反过来又归结为赚钱买票的问题。最后一个问题可以简化为找工作的问题。

Here are some other examples of reducibility. The problem of traveling from Boston to Paris is reduced to the problem of buying a plane ticket for a flight between the two cities. This problem is reduced to the problem of earning the money for the ticket. This last problem is reduced to the problem of finding a job.

数学问题中也存在可还原性。例如,测量矩形面积的问题被简化为测量其宽度和高度的问题。求解线性方程组的问题被简化为求逆矩阵的问题。

Reducibility also occurs in mathematical problems. For example, the problem of measuring the area of ​​a rectangle reduces to the problem of measuring its width and height. The problem of solving a system of linear equations reduces to the problem of finding the inverse matrix.

可归约性在根据问题的可判定性对问题进行分类以及后来的复杂性理论中发挥着重要作用。当问题A可简化为问题B时,解决方案A不可能比解决方案B更困难因为解决问题B会给出解决方案A。用计算理论的语言来说,如果问题A可以简化为问题B并且B是可判定的,那么A也是可判定的。同样,如果A不可判定且可简化为B,则问题B也是不可判定的。第二种解释是论证各种问题不可判定的关键。

Reducibility plays an important role in classifying problems by their decidability, and also later in complexity theory. When problem A is reducible to problem B , the solution to A cannot be more difficult than the solution to B , since solving problem B gives the solution to A . In the language of computational theory, if problem A is reducible to problem B and B is decidable, then A is also decidable. Equivalently, if A is undecidable and reducible to B , then problem B is also undecidable. This second interpretation is the key to proving that various problems are undecidable.

简而言之,我们证明某个问题不可判定的方法将在于证明我们可以将我们已经知道不可判定的其他问题简化为该问题。

In short, our method of proving that a certain problem is undecidable will consist in showing that it is possible to reduce to that problem some other problem which we already know to be undecidable.

5.1

语言理论中无法解决的问题

5.1

Undecidable Problems of the Theory of Languages

我们已经展示了ATM不可判定性,即确定图灵机是否接受给定输入的问题。考虑相关的HALT TM问题,即确定图灵机对于给定输入是否停止(接受或拒绝)的问题。这个问题被广泛称为停止问题。我们将利用语言A TM的不可判定性,通过将A TM简化为HALT TM来证明停止问题的不可判定性。让

We have already shown the undecidability of A TM , the problem of determining whether a Turing machine accepts a given input. Let us consider the related problem HALT TM , the problem of determining whether a Turing machine halts (accepting or rejecting) for a given input. This problem is widely known as the halting problem . We will use the undecidability of the language A TM to prove the undecidability of the halting problem, reducing A TM to HALT TM . Let

HALT TM = { M , w M是图灵机,M停止输入字w }。

HALT TM = { M , w : M is a Turing machine and M halts for input word w }.

定理5.1

Theorem 5.1

HALT TM语言是不可判定的。

The HALT TM language is undecidable.

证明的概念 间接证明。我们假设HALT TM是可判定的,并且我们用这个假设来证明A TM是可判定的,这与定理4.11不一致。关键思想是证明A TM可简化为HALT TM

Concept of Proof Proof by contradiction. We assume that HALT TM is decidable, and we use this assumption to show that A TM is decidable, which contradicts Theorem 4.11. The key idea is to show that A TM is reducible to HALT TM .

假设我们有一台解析HALT TM语言的图灵机R。然后我们将使用R构造一个解析A TM的机器S。为了理解我们如何构建S,让我们想象我们是机器S。我们的任务是解析A TM语言。我们得到一个形式为M , w 的输入。如果M接受in ,我们必须返回Accept ,如果M循环或拒绝in ,我们必须返回拒绝。让我们尝试为w模拟M。如果这台机器接受或拒绝,我们也会这样做。但是,我们无法确定M是否已循环,在这种情况下,模拟将不会终止。但这很糟糕,因为我们扮演解析机的角色,因此永远无法回环。所以这个想法本身是行不通的。

Suppose we have a Turing machine R that resolves the language HALT TM . We then use R to construct a machine S that resolves the language A TM . To understand how we will construct S , imagine that we are the machine S . Our task is to resolve the language A TM . We are given an input of the form M , w . We must return accept if M accepts w , and we must return reject if M loops or rejects w . Let's try to simulate M for w . If the machine accepts or rejects, we do the same. However, we are unable to decide whether M has looped, in which case the simulation will not terminate. However, this is wrong, because we are playing the role of a resolver, and therefore we can never loop. So this idea does not work by itself.

相反,我们将使用这样的假设:我们有一个可以解析HALT TM语言的图灵机R。给定R,我们可以测试M是否在输入单词停止。如果R表示M不会针对输入单词w停止,我们会拒绝它,因为在这种情况下M , w 不属于A TM。然而,如果R指示M将针对输入词w停止,那么我们就可以执行模拟而不会出现循环威胁。

Instead, we will use the assumption that we have a Turing machine R that decides the language HALT TM . Given R , we can test whether M halts for input word w . If R indicates that M does not halt for input word w , then we reject it, since in this situation M , w does not belong to A TM . On the other hand, if R indicates that M halts for input word w , then we can perform the simulation without the threat of looping.

因此,如果有一台机器R,我们可以解析语言A TM,但我们已经知道A TM是不可判定的。从这个矛盾我们可以得出R不存在的结论。因此,HALT TM是不可判定的。

So if there were a machine R , we could decide the language A TM , but we already know that A TM is undecidable. From this contradiction we can conclude that R does not exist. Therefore HALT TM is undecidable.

证明 为了反驳,让我们假设某个图灵机R可以解析HALT TM。我们将构造一个图灵机S来解析A TM,操作如下。

Proof For the sake of contradiction, suppose that some Turing machine R decides HALT TM . We construct a Turing machine S deciding A TM , which operates as follows.

S = "对于输入单词M , w 〉 ,即机器M和单词w的编码:

S = "For an input word M , w , that is, the encoding of the machine M and the word w :

  1. 启动R机器输入单词M , w
  2. Run the R machine for the input word M , w .
  3. 如果R拒绝输入单词,则拒绝
  4. If R rejects the input word, reject .
  5. 如果R接受,则为单词w模拟M,直到停止。
  6. If R accepts, then simulate M for word w until it stops.
  7. 如果M已接受输入,则接受;如果M拒绝输入,则拒绝“。
  8. If M accepted the input, accept ; if M rejected the input, reject ".

显然,如果R决定了HALT TM,那么S就会决定A TM。由于A TM是不可判定的,HALT TM也必须是不可判定的。

It is obvious that if R resolved HALT TM , then S would resolve A TM . Since A TM is undecidable, HALT TM must also be undecidable.

定理 5.1 说明了我们证明某个问题不可判定的策略。这种策略是大多数不可判定性证明的典型,除了语言A TM本身的不可判定性证明之外,我们直接通过对角化方法证明了这一点。

Theorem 5.1 illustrates our strategy for proving that a certain problem is undecidable. This strategy is typical for most undecidability proofs except for the proof of the undecidability of the language A TM itself , which we proved directly by the method of diagonalization.

我们现在将提出一些其他定理及其证明,作为使用可还原性方法证明不可判定性的进一步示例。让

We will now present several other theorems and their proofs as further examples of the use of the method of reducibility in proving undecidability. Let

E TM = { M M是图灵机且L ( M ) = Ø }。

E TM = { M : M is a Turing machine and L ( M ) = Ø }.

定理5.2

Theorem 5.2

E TM语言是不可判定的。

The E TM language is undecidable.

证明的概念 我们将使用定理 5.1 证明中采用的模式。我们假设E TM是可判定的,然后证明A TM是可判定的,这就产生了矛盾。令R为解析E TM 的图灵机。我们将使用R构造一个解析A TM的机器S。当 S 接收到输入M , w 〉时,它将如何?

Concept of the Proof We will use the pattern adopted in the proof of Theorem 5.1. We will assume that E TM is decidable and then show that A TM is decidable, which yields a contradiction. Let R be a Turing machine that decides E TM . We will use R to construct a machine S that decides A TM . How will S actwhen it receives an inputM , w ?

第一个想法是S对输入单词M 运行R并查看它是否接受。如果是这样,我们就会知道L ( M ) 是空的,因此M不接受w。然而,如果R拒绝M ,我们只会知道L ( M ) 不为空,因此M接受某个单词 - 但我们仍然不知道M是否接受中的特定单词。我们需要使用不同的方法。

The first idea is for S to run R for an input word M and check whether it accepts. If it does, we know that L ( M ) is empty, and so M does not accept w . However, if R rejects M , we only know that L ( M ) is not empty, and so M accepts some word—but we still do not know whether M accepts a particular word w . We need to use a different approach.

我们将修改<M>运行R 而不是对<M>运行R。我们将更改<M>保证M拒绝除w之外所有单词,但对于单词w它将像以前一样工作。然后我们将使用R来确定修改后的机器是否识别空语言。该机器唯一可以接受的单词是w,因此当且仅当它接受w时,它的语言才是非空的。当R在提供了修改后的机器的描述作为输入后接受时,我们将知道该机器不接受任何内容,因此M不接受中的单词。

Instead of running R for M , we run R on the modification M . We modify M to guarantee that M rejects all words except w , but works as before for the word w . We then use R to determine whether the modified machine recognizes an empty language. The only word the machine could accept is w , so its language is nonempty if and only if it accepts w . If R accepts when supplied with a description of the modified machine as input, we know that the machine accepts nothing, and therefore that M does not accept the word w .

证明 我们将使用我们的标准符号来描述证明概念中描述的修改后的机器。我们将这台机器称为M 1

Proof We will describe the modified machine presented in the proof concept using our standard notation. We will call this machine M 1 .

M 1 =“对于输入字x

M 1 = "For input word x :

  1. 如果x w,则拒绝
  2. If x w , reject .
  3. 如果x = w ,则针对输入字w运行M并 在M接受时接受
  4. If x = w , run M for input word w and  accept if M accepts.

该机器的描述中包含单词w 。 x = w的测试是通过查看输入单词并将其逐个字符与单词w进行比较来确定它们是否相同来以明显的方式执行的。

This machine includes the word w as part of its description. It tests whether x = w in the obvious way by looking at the input word and comparing it character by character with the word w to determine whether they are identical.

结合上述考虑,我们假设机器R解析E TM,并构造一个解析语言A TM的机器S,工作如下。

Combining the above considerations, we assume that the machine R decides E TM , and construct a machine S that decides the language A TM , operating as follows.

S = "对于输入单词M , w ,即图灵机M和单词w的编码:

S = "For an input word M , w , that is, the encoding of the Turing machine M and the word w :

  1. 使用机器描述M和单词w构造上述图灵机M 1
  2. Use the description of the machine M and the word w to construct the Turing machine M 1 described above .
  3. 对输入词M 1 运行R
  4. Run R for input word M 1 .
  5. 如果R接受,则拒绝;如果R拒绝,则接受。”
  6. If R accepts, reject ; if R rejects, accept ."

请注意,S必须能够根据描述M和单词w计算描述M 1。它可以做到这一点,因为它只需要向机器M添加额外的状态来执行x = w 的检查。

Note that S must be able to compute a description of M 1 from a description of M and a word w . It can do this because it only needs to add additional states to M that perform the check that x = w .

如果R是E TM的解析机,则 S将是A TM的解析机。然而, A TM的确定性机器不存在,因此我们知道语言E TM必定是不可确定的。

If R were a deciding machine for E TM , S would be a deciding machine for A TM . However, a deciding machine for A TM cannot exist, so we know that the language E TM must be undecidable.

涉及图灵机的另一个有趣的计算问题是确定给定图灵机是否识别一种也可以被更简单的计算模型识别的语言的问题。例如,令REGULAR TM为确定给定图灵机是否具有与其等效的有限自动机的问题。这个问题相当于确定给定图灵机是否识别正则语言的问题。让

Another interesting computational problem involving Turing machines is the problem of determining whether a given Turing machine recognizes a language that can also be recognized by a simpler computational model. For example, let REGULAR TM be the problem of determining whether a given Turing machine has an equivalent finite automaton. This problem is equivalent to the problem of determining whether a given Turing machine recognizes a regular language. Let

REGULAR TM = { <M> M是图灵机,L ( M )正则语言}。

REGULAR TM = { M : M is a Turing machine and L ( M ) is a regular language}.

定理 5.3

Theorem 5.3

REGULAR TM是一种不可判定的语言。

REGULAR TM is an undecidable language.

证明的概念 与不可判定性定理中常见的情况一样,该证明基于语言A TM的简化。我们假设REGULAR TM可以由某个图灵机R判定,并使用此假设构建解析A TM的机器S然而,这一次使用R的功能来构建S的效果就不那么明显了。尽管如此,它还是可以实现的。

Concept of the Proof As usual in undecidability theorems, this proof relies on a reduction of the language A TM . We assume that REGULAR TM is decidable by some Turing machine R , and we use this assumption to construct a machine S that decides A TM . This time, however, using the capabilities of R to construct S is less obvious. Nevertheless, it can be achieved.

这个想法是让机器S将单词M , w 作为输入并修改M,以便当且仅当M接受w时,结果机器才能识别正则语言。我们将修改后的机器称为M 2。当M不接受单词w时,我们将构造M 2来识别非正则语言 { 0 n 1 n : n ≥ 0} ,并在M接受w时识别正则语言Σ *。我们需要确定S如何从M i w构建这样一台机器M 2。我们构造M 2,使其自动接受属于 { 0 n 1 n : n ≥ 0} 的所有单词。此外,如果M接受w,则M 2接受所有其他单词。

The idea is for a machine S to take as input a word M , w and modify M so that the resulting machine recognizes a regular language if and only if M accepts w . We will call the modified machine M 2 . We construct M 2 so that it recognizes the irregular language { 0 n 1 n : n ≥ 0} when M does not accept w , and recognizes the regular language Σ * when M accepts w . We need to determine how S can construct such a machine M 2 from M and w . We construct M 2 so that it automatically accepts all words in { 0 n 1 n : n ≥ 0}. In addition, if M accepts w , then M 2 accepts all the remaining words.

请注意,我们构建M 2机器并不是为了实际运行它来获取某些输入 - 这是一个常见的误解。我们构造M 2只是为了表明我们可以将其描述传递给我们假设存在的REGULAR TM语言解析机,并根据其计算结果确定 M 是否接受 w ,因此我们可以解析语言A TM,这是一个矛盾。

Note that we do not construct the machine M 2 in order to actually run it for some input—this is a common misunderstanding. We construct M 2 merely to show that we could pass its description to a machine deciding the language REGULAR TM , which we have assumed exists, and from the result of its computations determine whether M accepts w. This would allow us to decide the language A TM , which is a contradiction.

证明 R为求解REGULAR TM 的Turgin 机;一个机器S来解析AT M。机器S的工作原理如下。

Proof Let R be a Turgini machine deciding REGULAR TM ; we construct a machine S deciding AT M . Machine S operates as follows.

S = "对于输入单词M , w ,其中M是图灵机,w是单词:

S = "For an input word M , w , where M is a Turing machine and w is a word:

  1. 我们构建以下图灵机M 2

    M 2 = 对于输入字x

    1. 如果x的形式为0 n 1 n则接受
    2. 如果x不具有此形式,则对输入单词w运行M并 在M接受w时接受
  2. We construct the following Turing machine M 2 .

    M 2 = For input word x :

    1. If x is of the form 0 n 1 n , accept .
    2. If x is not of this form, run M for input word w and  accept if M accepts w .
  3. 对输入单词M 2 运行R
  4. Run R for input word M 2 .
  5. 如果R接受输入,则接受;如果R拒绝,则拒绝'.
  6. If R accepts the input, accept ; if R rejects, reject ".

以类似的方式,我们可以证明检查图灵机的语言是否是上下文无关的、可判定的甚至有限语言的问题的不可判定性。甚至还有一个称为赖斯定理的通用结果,该定理指出,确定图灵机识别的语言的任何属性都是不可判定的。我们将在问题 5.28 中介绍莱斯定理。

In a similar way, one can prove the undecidability of the problems of checking whether the language of a Turing machine is a context-free, decidable, or even finite language. There is even a general result called Rice's theorem, which states that determining any property of languages ​​recognized by Turing machines is undecidable. We will present Rice's theorem in Problem 5.28.

到目前为止,我们证明语言不可判定性的策略已经使用了A TM 的约简。有时候,当我们想要证明某些语言是不可判定的时,从另一种不可判定的语言进行归约可能会更方便,比如E TM。定理 5.4 表明,检查两台图灵机的等价性是一个不可判定的问题。我们可以通过从A TM减少来证明这一点,但我们将借此机会提供一个通过从E TM减少来证明不可判定性的例子。让

So far, our strategy for proving the undecidability of languages ​​has involved reductions from A TM . Sometimes, when we want to prove that some languages ​​are undecidable, it may be more convenient to reduce from another undecidable language, such as E TM . Theorem 5.4 shows that checking the equivalence of two Turing machines is an undecidable problem. We could prove this by reduction from A TM , but we will take the opportunity to give an example of a proof of undecidability by reduction from E TM . Let

EQ TM = { M 1 , M 2 | M 1M 2是图灵机并且L ( M 1 ) = L ( M 2 )}。

EQ TM = { M 1 , M 2 | M 1 and M 2 are Turing machines and L ( M 1 ) = L ( M 2 )}.

定理5.4

Theorem 5.4

EQ TM语言是不可判定的。

The EQ TM language is undecidable.

证明的概念 我们将证明,如果EQ TM是可判定的,那么E TM也将是可判定的,代表从E TMEQ TM的减少。这个想法很简单。 E TM是判断图灵机的语言是否为空的问题。 EQ TM是判断两台图灵机的语言是否相同的问题。如果其中一种语言结果是Ø,我们就会面临另一种语言是否为空的问题——即E TM问题。因此, E TM问题可以被认为是EQ TM问题的特殊情况,其中一台机器识别空语言。这个想法使我们能够轻松地制定约简。

The Concept of the Proof We will show that if EQ TM were decidable, then E TM would also be decidable by showing a reduction from E TM to EQ TM . The idea is simple. E TM is the problem of determining whether the language of a Turing machine is empty. EQ TM is the problem of determining whether the languages ​​of two Turing machines are the same. If one of these languages ​​turns out to be Ø , then we would be faced with the problem of whether the other language is empty—that is, the problem of E TM . Thus, we can consider the problem of E TM to be a special case of the problem of EQ TM in which one of the machines recognizes an empty language. This idea allows us to formulate the reduction easily.

Dwór 我们假设图灵机R解析EQ TM ,并且我们构建一个解析E TM的机器S,其工作原理如下。

We assume that a Turing machine R decides EQ TM and construct a machine S deciding E TM that operates as follows.

S = "对于输入词M ,其中M是图灵机:

S = "For input word M , where M is a Turing machine:

  1. 我们对输入单词M , M 1 〉运行R,其中M 1是丢弃所有输入单词的图灵机。
  2. We run R for an input word M , M 1 , where M 1 is a Turing machine rejecting all input words.
  3. 如果R接受,则接受;如果R拒绝,则拒绝'.
  4. If R accepts, accept ; if R rejects, reject ."

如果R解析EQ TM,则S解析E TM。然而,根据定理 5.2,语言E TM是不可判定的,因此EQ TM也必须是不可判定的。

If R decides EQ TM , then S decides E TM . However, by Theorem 5.2 the language E TM is undecidable, therefore EQ TM must also be undecidable.

通过计算历史减少

Reductions by computation histories

计算历史方法是证明A TM可简化为某些语言的重要技术。当我们想要证明的问题是不可判定的、涉及检查某个数学对象是否存在时,这种方法通常很有用。例如,该方法用于证明希尔伯特第十个问题的不可判定性,即检查给定多项式是否具有整数根的问题。

The method of the history of computation is an important technique for proving that A TM is reducible to certain languages. This method is often useful when the problem whose undecidability we wish to prove involves testing whether a certain mathematical object exists. For example, this method was used to show the undecidability of Hilbert's tenth problem, the problem of testing whether a given polynomial has integer roots.

图灵机对于给定输入的计算历史只是机器在处理输入时所经历的配置序列。这是该机器执行的计算的完整记录。

The computational history of a Turing machine for some input is simply the sequence of configurations that the machine goes through in processing the input. It is a complete record of the computations performed by the machine.

定义 5.5

Definition 5.5

M为图灵机,w 为输入词。机器Mw的接受计算历史是配置序列C 1 , C 2 , …, C l,其中C 1是Mw的初始配置,C l是接受M 的配置,并且每个C i正确根据机器M的规则,遵循C i −1 。机器Mw的丢弃计算历史的定义类似,只是C l是丢弃配置。

Let M be a Turing machine and w an input word. The accepting computation history of M for w is the sequence of configurations C 1 , C 2 , …, C l , where C 1 is the initial configuration of M for w , C l is an accepting configuration of M , and each C i follows C i −1 correctly , according to the rules of M . The rejecting computation history of M for w is defined analogously except that C l is a rejecting configuration.

配置历史是有限序列。如果M在处理w时没有停止,则机器M不存在接受或拒绝 w 的计算历史。确定性机器对于每个输入至多有一个计算历史。非确定性机器对于单个输入可以有多个计算历史,对应于不同的计算路径。从现在开始,我们将专注于确定性机器。我们使用计算方法的历史来证明不可判定性的第一个证据涉及一种称为线性有界自动机的机器。

Configuration histories are finite sequences. If M does not halt while processing w , then there is no accepting or rejecting computation history of M for w . Deterministic machines have at most one computation history for each input. Nondeterministic machines may have multiple computation histories for a single input, corresponding to different computation paths. From now on, we focus on deterministic machines. Our first proof of undecidability using the computation history method concerns a type of machine called a linear bounded automaton.

定义 5.6

Definition 5.6

线性有界自动机(LBA) 是一种图灵机,其中磁带头不能移动超出包含输入数据的磁带部分。如果机器试图将磁头移动到输入的任一端之外,它会停留在同一位置 - 类似于普通图灵机中磁头不会移动到磁带左端之外1

A linear bounded automaton (LBA) is a type of Turing machine in which the tape head is not allowed to move beyond the part of the tape containing the input data. If the machine tries to move the head beyond either end of the input data, it stays in the same place—analogous to the head not moving beyond the left end of the tape in an ordinary Turing machine 1 .

线性有界机是具有有限内存量的图灵机,如下图所示。它可以解决需要适合用于存储输入单词的磁带区域的内存的问题。使用大于输入字母表的磁带字母表可以使可用内存增加一个常数因子。因此,我们说,对于长度为 n 的输入字可用内存的大小是n 的线性函数- 因此该模型的名称。

A linearly bounded automaton is a Turing machine with a limited amount of memory, as schematically shown in the figure below. It can solve problems requiring memory that fits into the area of ​​the tape used to write the input word. Using a tape alphabet larger than the input alphabet allows the available memory to be increased by a constant factor. We therefore say that for an input word of length n, the size of the available memory is a linear function of n - hence the name of this model.

5.7

线性有界自动机示意图

Figure 5.7

Schematic diagram of a linearly bounded automaton

尽管存在内存限制,线性有界自动机 (LBA) 仍具有相当大的计算能力。例如, A DFAA CFGE DFAE CFG语言的决胜局是 LBA。任何 CFL 语言都可以使用 LBA 进行解析。事实上,需要付出一些努力才能找到一种无法被某些 LBA 解析的可判定语言。第 9 章将介绍完成此类任务的技术。

Despite their memory limitations, linear bounded automata (LBA) have considerable computational power. For example, the decidable machines for the languages ​​A DFA , A CFG , E DFA , and E CFG are all LBAs. Any CFL language can be decidable using LBA. In fact, finding a decidable language that cannot be decidable by some LBA takes some effort. We present techniques for doing this in Chapter 9.

这里讨论的A LBA语言是确定LBA是否接受其输入单词的问题。尽管A LBA看起来与不可判定问题A TM几乎相同,其中图灵机仅限于 LBA 类,但我们可以证明A LBA是可判定的。让

The language A LBA discussed here is the problem of determining whether LBA accepts its input word. Although A LBA looks almost exactly like the undecidable problem A TM , in which the Turing machine has been restricted to the class LBA, we can show that A LBA is decidable. Let

A LBA = { M , w M是接受单词w }的 LBA 。

A LBA = { M , w : M is an LBA that accepts word w }.

以下引理将有助于证明A LBA的可判定性。它指出,当 LBA 的输入是长度为n的字时,它只能有有限数量的配置。

The following lemma is useful to prove the decidability of A LBA . It states that LBA can have only a finite number of configurations when its input is a word of length n .

引理 5.8

Lemma 5.8

M为 LBA,具有属于磁带字母表的q个状态和g 个符号。对于长度为n的磁带,机器M正好有qng n 个不同的配置。

Let M be an LBA with q states and g symbols belonging to the tape alphabet. There are exactly qng n different configurations of the machine M for a tape of length n .

证明 回想一下,配置M类似于计算过程中拍摄的快照。配置由当前状态、磁头位置和磁带内容组成。在这种情况下, Mq 个状态。磁带的长度为n,因此磁头可以位于n 个位置之一,并且磁带上可以出现g n 个可能的磁带符号序列。这三个量的乘积是带有长度为n的带子的机器M的不同配置的总数。

Proof Recall that a configuration M is something like a snapshot taken during its computation. The configuration consists of the current state, the head position, and the tape contents. In this case, M has q states. The tape length is n , so the head can be in any one of n positions, and there can be g n possible tape symbol sequences on the tape. The product of these three quantities is the total number of different configurations of machine M with a tape of length n .

定理5.9

Theorem 5.9

A LBA语言是可判定的。

The A LBA language is decidable.

证明的概念 为了能够确定 LBA M是否接受输入w ,我们将模拟M对单词w的操作。如果在模拟过程中机器M停止并接受或拒绝,我们也会相应地接受或拒绝。当M循环查找中的单词时,困难就出现了。我们需要能够检测循环,以便我们可以停止操作并丢弃输入单词。

Proof Concept To decide whether LBA M accepts input w , we simulate the operation of M for word w . If during this simulation the machine M stops and accepts or rejects, we also accept or reject accordingly. The difficulty arises when M loops for word w . We need to be able to detect the loop so that we can stop and reject the input word.

机器M的循环检测的思想是,当M对w执行计算时,它会从一个配置移动到另一个配置。如果M重复某个配置,那么一段时间后它将再次重复该配置,因此将处于循环中。由于M是LBA,可用的磁带长度是有限的。根据引理 5.8,M在这个长度的磁带上只能有有限数量的配置。因此,在M重新进入之前的某个配置之前,只有有限的可用时间。通过根据引理 5.8 给出的步数模拟M,可以检测M的循环。如果M到此为止还没有停止,则其操作必须循环。

The idea of ​​detecting a loop in a machine M is that as M computes for w , it moves from configuration to configuration. If M ever repeats a certain configuration, then after some time it will repeat that configuration again and thus enters a loop. Since M is LBA, the length of the available tape is bounded. By Lemma 5.8, M can have only a finite number of configurations on a tape of that length. Thus, only a finite time is available before M reenters some configuration it was in before. Detecting a loop in M ​​is possible by simulating M for a number of steps given by Lemma 5.8. If M does not stop by that point, its execution must loop.

证明A LBA 决胜算法如下所示。

Proof The A LBA deciding algorithmis shown below.

L = "对于输入单词M , w ,其中M是 LBA,w是一个单词:

L = "For input word M , w , where M is LBA and w is a word:

  1. 模拟机器M输入字w qng n步或直到停止
  2. Simulate machine M for input word w for qng n steps or until it stops.
  3. 如果机器M已经停止,如果接受则接受,如果拒绝则拒绝。如果还没有停止,则丢弃
  4. If machine M has stopped, accept if it has accepted, or reject if it has rejected. If it has not stopped, reject ”.

如果机器M在qng n步后还没有停止,那么根据引理 5.8,它必须重复一些配置,从而进入循环。因此我们的算法在这种情况下会拒绝。

If machine M has not halted after executing qng n steps, then by Lemma 5.8 it must repeat some configuration and thus enters a loop. Therefore, our algorithm rejects in this case.

定理 5.9 表明 LBA 与图灵机有根本的不同。对于 LBA 来说,接受问题是可判定的,但对于图灵机来说却不是。然而,有关 LBA 的某些其他问题仍未解决。其中之一是空语言问题E LBA = { M M是 LBA,其中L ( M ) = Ø }。为了证明E LBA是不可判定的,我们将使用计算历史方法来展示缩减。

Theorem 5.9 shows that LBAs are fundamentally different from Turing machines. For LBAs the acceptance problem is decidable, while for Turing machines it is not. However, some other problems concerning LBAs remain undecidable. One of them is the empty language problem E LBA = { M : M is an LBA for which L ( M ) = Ø }. To show that E LBA is undecidable, we show a reduction using the computational history method.

定理5.10

Theorem 5.10

E LBA是不可判定的。

E LBA is undecidable.

证明的概念该证明使用A TM 的约简。我们将证明,如果E LBA是可判定的,那么A TM也将是可判定的。我们假设E LBA是可判定的。我们如何使用这个假设来解决A TM问题?

Concept of Proof This proof uses a reduction from A TM . We will show that if E LBA were decidable, A TM would also be decidable. We will assume that E LBA is decidable. How could we use this assumption to decide A TM ?

对于图灵机M和输入w,我们可以通过构造一些 LBA B然后检查L ( B ) 是否为空来确定M是否接受w 。 B识别的语言将包含机器M对单词w的所有接受计算历史。如果M接受w,则该语言将包含一个单词,因此不会为空。如果M不接受w,则该语言将为空。因此很明显,如果我们能够确定机器B的语言是否为空,那么我们就可以确定M是否接受w

For a Turing machine M and input w , we can determine whether M accepts w by constructing some LBA B and then checking whether L ( B ) is empty. The language recognized by B will consist of all the accepting computation histories of M for a word w . If M accepts w , this language will contain a single word and so will not be empty. If M does not accept w , this language will be empty. It is therefore clear that if we could determine whether the language of B is empty, we could determine whether M accepts w .

我们现在将描述基于机器M和单词w 的机器B的构造。请注意,我们需要证明的不仅仅是B的存在。我们需要展示图灵机如何在给定机器M和单词w的描述的情况下构造机器B的描述。

We now describe the construction of an automaton B in terms of a machine M and a word w . Note that we need to show more than just the existence of B . We need to show how a Turing machine can construct a description of B , given a description of M and a word w .

正如我们之前用来证明不可判定性的简化一样,我们将构造机器B只是为了将其描述传递给假设的解析器机器E LBA,而不是实际运行它。

As in the previous reductions that we used to prove undecidability, we will construct the machine B only to pass its description to the hypothetical deciding machine E LBA , not to actually run it.

如果x是机器M对单词w的接受计算历史记录,我们将构造B来接受其输入x。回想一下,接受计算历史是机器M在接受中的某个单词时经历的一系列配置C 1 , C 2 , …, C l

We construct B so that it accepts its input x if x is the accepting computation history of M for a word w . Recall that the accepting computation history is the sequence of configurations C 1 , C 2 , …, C l that M traverses when accepting some word w .

对于这个证明,我们假设接受计算历史记录表示为单个单词,其中包含由#符号分隔的配置,如图 5.11 所示。

For the purposes of this proof, we assume that the accepting computation history is represented as a single word containing configurations separated by the symbol # , as in Figure 5.11.

5.11机器B

的可能输入

Figure 5.11

Possible input for machine B

LBA B 的工作原理如下。收到输入x后,如果x是机器M对单词w的接受计算历史记录,我们期望B接受。首先,B通过分隔符将x分成单词C 1C 2、...、C l。然后B检查每个C i是否满足接受计算历史的三个条件:

LBA B works as follows. Given an input x , we expect B to accept if x is an accepting computation history of machine M for word w . First, B partitions x by delimiters into words C 1 , C 2 , …, C l . Then, B checks whether each C i satisfies the three conditions of an accepting computation history:

  1. C 1是M 对于w 的初始配置。
  2. C 1 is the initial configuration M for w.
  3. 每个C+1都正确地跟随C
  4. Any C i +1 correctly follows a C i .
  5. C l是接受M台机器的配置。
  6. C l is the configuration accepting M machines .

机器Mw的初始配置C 1是单词q 0 w 1 w 2w n,其中q 0是M的初始状态。在这种情况下,B自身内置了这个词,因此它能够检查第一个条件。接受配置是包含状态qaccept配置,因此B可以通过在Cl中搜索qaccept来检查第三个条件。检查第二个条件是最困难的。对于每对相邻配置,B检查C i +1是否正确遵循C i。此步骤验证除了头部下方的位置和相邻位置之外,C iC i +1相同。这些位置的变化必须根据机器的传递函数M发生。 B通过在配置C iC i +1中的适当位置之间曲折来检查这些更改是否已正确进行。为了在之字形移动时跟踪您的当前位置,B在磁带上用点标记您的当前位置。最后,如果满足条件 1、2 和 3,则B接受其输入。

The initial configuration C 1 of machine M for w is the word q 0 w 1 w 2w n , where q 0 is the initial state of M . In this case, B contains this word embedded in itself and so is able to check the first condition. An accepting configuration is one that contains the state q accept , so B can check the third condition by searching the word C l for q accept . Checking the second condition is the most difficult. For each pair of adjacent configurations, B checks whether C i +1 correctly follows C i . This step verifies that C i and C i +1 are identical except for the position under the head and the adjacent positions. The change in these positions must occur according to the transition function of machine M . B checks that these changes were made correctly by zigzagging between the corresponding positions in configurations C i and C i +1 . To keep track of the current position during the zigzagging, B marks the current position with dots on the tape. Finally, if conditions 1, 2, and 3 are met, then B accepts its input.

通过对决胜机返回的结果取反,我们可以得到机器M是否接受w 的答案。这意味着我们可以解决语言A TM - 矛盾。

By inverting the result returned by the deciding machine, we get the answer whether the machine M accepts w . This means that we can decide the language A TM – a contradiction.

证明我们现在可以将问题A TM 简化为E LBA。假设图灵机R解析E LBA。根据下面的程序解析A TM 的机器S。

Proof We can now show the reduction of the problem A TM to E LBA . Suppose a Turing machine R decides E LBA . We construct a machine S that decides A TM according to the following program.

S = "对于输入单词M , w ,其中M是 TM,w是单词:

S = "For input word M , w , where M is a TM and w is a word:

  1. 如证明概念中所述,从Mw构造 LBA B。
  2. Construct LBA B from M and w as described in the proof concept.
  3. 对输入单词B 运行R
  4. Run R for input word B .
  5. 如果R拒绝输入,则接受;如果R接受输入,则拒绝'.
  6. If R rejects input, accept ; if R accepts input, reject ".

如果R接受B ,则意味着L ( B ) = Ø。因此,机器M不存在接受单词w的计算历史,因此M不接受w。因此,S拒绝M , w 。同样,如果R拒绝B 〉 ,则机器B的语言不为空。B唯一可以接受的词是机器Mw的接受计算历史。由此可见M必须接受w。因此,S接受M , w 。 LBA B如图 5.12 所示。

If R accepts B , then L ( B ) = Ø . Thus there is no accepting history of M for a word w , and therefore M does not accept w . Consequently S rejects M , w . And similarly, if R rejects B , then the language of B is not empty. The only word that B can accept is the accepting history of M for w . It follows that M must accept w . Consequently S accepts M , w . LBA B is illustrated in Figure 5.12.

5.12

LBA B检查图灵机的计算历史

Figure 5.12

LBA B checking the computation history of a Turing machine

计算历史的缩减技术还可用于使涉及上下文无关语法和堆叠自动机的某些问题变得不可判定。我们记得,在定理 4.8 的证明中,我们提出了一种算法,用于检查上下文无关语法是否生成任何单词,即是否L ( G ) = Ø。我们现在将证明类似的问题是不可判定的。这就是确定上下文无关语法是否生成所有可能单词的问题。证明这个问题是不可判定的,是证明上下文无关文法等价问题不可判定的主要步骤。让

The techniques of reduction by histories of computation can also be used to prove the undecidability of certain problems concerning context-free grammars and pushdown automata. Recall that in the proof of Theorem 4.8 we gave an algorithm to check whether a context-free grammar generates any words, that is, whether L ( G ) = Ø . We now show that a similar problem is undecidable. This is the problem of determining whether a context-free grammar generates all possible words. Showing that this problem is undecidable is the main step in proving that the equivalence problem of context-free grammars is undecidable. Let

ALL CFG = { G G是 CFG 的语法,L ( G ) = Σ * }。

ALL CFG = { G : G is a CFG grammar and L ( G ) = Σ * }.

定理5.13

Theorem 5.13

ALL CFG是不可判定的。

ALL CFG is undecidable.

证明 我们将间接证明。为了引发矛盾,我们假设ALL CFG是可判定的,并且我们用这个假设来证明A TM是可判定的。这个证明与定理 5.10 的证明类似,但有一个额外的小步骤:它是通过计算历史对A TM进行约简,但出于我们稍后将解释的技术原因,我们将稍微修改我们表示计算历史的方式。

Proof We will show an indirect proof. To achieve a contradiction, we assume that ALL CFG is decidable, and we use this assumption to show that A TM is decidable. This proof is similar to the proof of Theorem 5.10, but with a small additional step: it is a reduction from A TM by the history of computation, but for a technical reason that we will explain later, we slightly modify the way we represent the history of computation.

现在我们将描述如何使用ALL CFG解析过程来解析A TM。对于图灵机M和输入单词w,我们构造一个 CFG 语法G,当且仅当M不接受单词w时,它生成所有单词。因此,如果机器M接受w,那么G将不会生成某些特定的单词。这个词——令人惊讶的是——机器M对词w的接受计算历史。换句话说,G被设计为生成所有不属于机器M对单词w的计算历史的单词。

We now describe how we will use the ALL CFG adjudication procedure to adjudicate A TM . For a Turing machine M and an input word w , we construct a CFG grammar G that generates all words if and only if M does not accept the word w . Thus, if M accepts w , then G will not generate some particular word. This word is—surprise—the accepting computation history of M for the word w . In other words, G is designed to generate all words that are not the accepting computation history of M for the word w .

为了使CFG语法G生成所有不是机器Mw的接受计算历史的单词,我们将使用以下策略。由于多种原因,这个词可能不被接受的计算历史。回想一下,机器Mw的接受计算历史是# C 1 # C 2 ## C l #,其中C i是机器M在对单词w执行的计算的第 i步时的配置。所以G是生成单词

In order for the CFG grammar G to generate all words that are not the accepting computation history of machine M for w , we use the following strategy. A word may not be the accepting computation history of machine M for w for several reasons. Recall that the accepting computation history of machine M for w is of the form # C 1 # C 2 ## C l # , where C i is the configuration of machine M at the i -th computation step performed for word w . Thus, G is to generate words that

  1. 不要以C 1开头,
  2. do not start with C 1 ,
  3. 不以接受配置结束,
  4. do not end with an accept configuration,
  5. 其中,根据运算规则M,某些C不能正确导出C+1
  6. in which, according to the rules of operation of M , a certain C i does not lead correctly to C i +1 .

如果M不接受w,则不存在接受计算历史记录,因此所有单词都以某种方式不符合这些条件。因此,在这种情况下,G将生成所有单词,正如我们假设的那样。

If M does not accept w , then there is no accepting computation history, so all words somehow fail to satisfy these conditions. Therefore, in such a situation, G will generate all words, as we postulate.

我们现在继续构建G。我们将构建 PDA D,而不是直接构建G。我们知道,我们可以使用定理 2.20(第 117 页)证明中给出的构造将D转换为 CFG 语法。我们这样做是因为在我们的例子中构建 PDA 比构建 CFG 语法更容易。在这种情况下,D将从一个非确定性分支开始,猜测要检查之前提出的三个条件中的哪一个。一条路径检查输入单词的开头是否是C 1,如果不是则接受。第二条路径检查输入字是否以包含状态q accept的机器配置M结尾,如果不是则接受。

We now proceed to construct G . Instead of constructing G directly, we construct a PDA D . We know that we can use the construction given in the proof of Theorem 2.20 (page 117) to transform D into a CFG grammar. We do this because, in our case, constructing a PDA is easier than constructing a CFG grammar. In this case, D will start with a nondeterministic branch, guessing which of the three conditions presented earlier to check. One path checks whether the input word starts with C 1 , and accepts if it does not. The other path checks whether the input word ends with a configuration of M containing the state q accept , and accepts if it does not.

第三条路径是如果C未正确输出以下C+1,则接受输入字。自动机通过遍历输入直到它不确定地决定它已达到配置C来实现此目的。然后它将编码C的后续符号放入堆栈中,直到到达标有#符号的末尾。然后D从堆栈中删除符号以将它们与C+1的配置进行比较。正如我们所期望的,除了头部位置周围,它们应该在任何地方都匹配,其中的差异是由于机器传递函数M造成的。最终,如果 D 检测到配置之间存在不匹配或无效更改,则它会接受。

The third path is to accept an input word if any C i does not correctly output a subsequent C i +1 . The automaton does this by scanning the input until it decides nondeterministically that it has reached configuration C i . It then pushes successive symbols encoding C i onto the stack until it reaches the end of the stack, marked by the symbol # . D then pops symbols from the stack to compare them with configuration C i +1 . As we expect, they should match everywhere except near the head position, where the difference is due to the machine's transition function M . Finally, D accepts if it detects a mismatch or an illegal change between the configurations.

然而,这种证明思想存在一个问题:当D从堆栈中弹出C i时,其元素顺序相反,不适合与C i +1进行比较。这就是前面提到的技巧发挥作用的地方:否则我们将保存接受计算历史记录。所有其他配置都将以相反的顺序包含元素。奇数配置将保持向前顺序,但偶数配置将向后保存。这样,接受计算历史将如下图所示。

There is a problem with this proof idea, however: when D pops C i from the stack, its elements are in reverse order and are not suitable for comparison with C i +1 . This is where the aforementioned trick comes in: we will write the accepting history of computation differently. Every second configuration will contain elements in reverse order. Odd configurations will remain written in forward order, but even configurations will be written backward. This way, the accepting history of computation will look like the one in the figure below.

5.14

每隔一个配置逆序写入

Figure 5.14

Every second configuration is saved in reverse order

通过这种修改后的形式,PDA 将能够将配置压入堆栈,以便稍后从堆栈中弹出该配置时,元素的顺序将适合于将其与下一个进行比较。我们将构造D来接受任何不接受修改形式的计算历史的单词。

With this modified form, the PDA will be able to push the configuration onto the stack, so that when it later pops it off the stack, the order of elements will be appropriate for comparing it with the next one. We will construct D to accept any word that is not an accepting computation history in the modified form.

在练习5.1中,我们将使用定理5.13来证明EQ CFG是不可判定的。

In Exercise 5.1 we will use Theorem 5.13 to prove that EQ CFG is undecidable.

5.2

一个简单的不可判定问题

5.2

Simple undecidable problem

在本节中,我们将证明不可判定性现象不仅限于与自动机相关的问题。我们将提供一个涉及字操作的不可判定问题的示例。这被称为邮政信件问题(PCP)。

In this section, we will show that the phenomenon of undecidability is not limited to problems related to automata. We will present an example of an undecidable problem related to operations on words. It is called the Post correspondence problem ( PCP).

我们可以将这个问题描述为一种谜题。我们从一组多米诺骨牌开始,每个多米诺骨牌包含两个单词,一个在顶部,一个在底部。一块石头可能看起来像这样:

We can describe this problem as a kind of puzzle. We start with a set of dominoes, each with two words, one on top and one on the bottom. A single domino might look like this:

一组多米诺骨牌可能看起来像这样:

and a set of dominoes might look like this:

任务是创建一个多米诺骨牌列表(允许重复),使得通过读取顶部符号获得的单词与底部的单词相同。我们将这样的列表称为匹配。例如,下面的列表是上面谜题的改编版。

The task is to create a list of dominoes (with allowed repetitions) in such a way that the word obtained by reading the symbols at the top is identical to the word at the bottom. We will call such a list a match . For example, the list below is a match for the above puzzle.

读取顶部字符串,我们得到abcaaabc,这与读取底部字符串相同。我们还可以通过扭曲多米诺骨牌来表示这种对齐方式,使得顶部和底部线上的相应符号垂直对齐。

Reading the top sequence gives abcaaabc , which is the same as reading the bottom sequence. We can also represent this alignment by distorting the dominoes so that corresponding symbols on the top and bottom lines are aligned vertically.

对于某些宝石收藏,可能无法找到匹配的宝石。例如,一个集合

For some sets of stones, finding a match may be impossible. For example, the set

不包含匹配项,因为每个顶部单词都比其对应的底部单词长。

does not contain a match because each top word is longer than its corresponding bottom word.

波斯特的适合性问题是确定一组给定的棋子是否存在匹配。这个问题无法通过算法解决。

Post's correspondence problem is to determine whether a matching exists for a given set of stones. This problem cannot be solved algorithmically.

在我们正式表述该定理及其证明之前,让我们尝试精确地表示它,然后将其表达为语言。 PCP 问题的一个例子是多米诺骨牌集合P

Before we get to the formal formulation of this theorem and its proof, let us try to state it precisely and then express it as a language. An instance of the PCP problem is the set P of dominoes

匹配的是序列i 1 , i 2 , …, i l,其中t i 1 t i 2t il = b i 1 b i 2b il。问题是判断P是否匹配。让

and a matching is a sequence i 1 , i 2 , …, i l , where t i 1 t i 2t il = b i 1 b i 2b il . The problem is to determine whether a matching exists for P. Let

PCP = { <P> P是具有匹配的Post适宜性问题的一个实例}

PCP = { P : P is an instance of Post's correspondence problem having a matching}.

定理5.15

Theorem 5.15

PCP是不可判定的。

PCP is undecidable.

证明的概念 就其思想而言,该证明虽然包含许多细节,但很简单。通过接受计算历史来减少A TM 。我们将证明,对于任何图灵机M和输入w,我们可以构造一个P实例,其匹配是机器Mw的接受计算历史。如果我们可以确定该实例是否有匹配项,那么我们就可以确定M是否接受w

Concept of the Proof In its idea, this proof is simple, although it contains many details. The basic idea is to reduce A TM by accepting computation histories. We show that for any Turing machine M and input w , we can construct an instance P whose matching is an accepting computation history of M for w . If we could determine whether this instance has a matching, then we could determine whether M accepts w .

如何构造P使得匹配是机器Mw的接受计算历史?我们以创建匹配强制创建模拟M的方式选择属于P的多米诺骨牌。在这种匹配中,每颗棋子将一个配置中的一个或多个位置与其在下一个配置中的对应位置相结合。

How can P be constructed so that the matching is an accepting history of the computations of M for w ? We choose the dominoes belonging to P in such a way that the formation of the matching forces the formation of a simulation of M . In this matching, each domino connects a position or positions in one configuration with its corresponding one(s) in the next configuration.

在开始构建P之前,我们需要解决三个小技术问题。 (当您最初熟悉这种构造时,不需要太担心它们。)首先,为了构造P的方便,我们假设w的M永远不会尝试将头部移动到超出该构造的左端之外。磁带。这就需要预先修改M以避免这种行为。其次,如果w = ε,我们将在构造中使用单词来代替。第三,我们将修改PCP,添加比赛从第一张多米诺骨牌开始的要求,

Before we begin constructing P , we need to address three minor technical issues. (You don't need to worry about them too much when you first start reading this construction.) First, for the convenience of constructing P , we assume that M for w never tries to move the head past the left end of the tape. This requires an initial modification of M to avoid this behavior. Second, if w = ε , we use the word instead in the construction . Third, we modify PCP to require that the matching starts with the first domino,

稍后我们将展示如何消除这一要求。我们将这个问题称为修改后对应问题(MPCP)。让

We will later show how to eliminate this requirement. We will call this problem the Modified Post Correspondence Problem (MPCP). Let

MPCP = { <P> P是Post匹配问题的一个实例,其中匹配从第一张多米诺骨牌开始}

MPCP = { P : P is an instance of Post's correspondence problem where the matching starts from the first domino }.

我们现在可以深入研究证明的细节并设计P来模拟机器M来处理单词w

We can now proceed to the details of the proof and design P to simulate the machine M for the word w .

证明 让图灵机R解析PCP。我们将构造一台机器S来解析A TM。让

Proof Let a Turing machine R decide PCP. We construct a machine S that decides A TM . Let

M = ( Q , Σ , Γ , δ , q 0 , q接受, q拒绝),

M = ( Q , Σ , Γ , δ, q 0 , q accept , q reject ),

其中QΣΓ、 δ 分别是状态集、输入字母表、磁带字母表和机器M的传递函数。

where Q , Σ , Γ , δ are the state set, the input alphabet, the tape alphabet and the transition function of the machine M , respectively .

机器S构造 PCP 问题P的一个实例,当且仅当M接受w时,该实例才具有匹配。为了实现这一点,S首先构造MPCP 问题的实例P' 。我们将分七个部分来描述这个结构,每个部分都将实现模拟M对单词w的操作的特定方面。为了更好地解释我们将要做什么,我们将在该结构中穿插一些示例,展示其工作原理。

A machine S constructs an instance of the PCP problem P that has a matching if and only if M accepts w . To accomplish this, S first constructs an instance P' of the MPCP problem. We will describe this construction in seven parts, each of which will achieve a particular aspect of the simulation of the action of M for a word w . To better explain what we are doing, we will intersperse the construction with examples that show how it works.

第 1 部分。我们按如下方式开始构建。

Part 1. We begin the construction as follows.

由于P'是 MPCP 的实例,因此比赛必须从这张多米诺骨牌开始。因此,较低的字以配置C 1 = q 0 w 1 w 2w n正确开头,这是机器M对字w的接受计算历史中的第一个配置,如下图所示。

Since P' is an instance of the MPCP, the matching must start with this domino. Therefore, the bottom word correctly starts with the configuration C 1 = q 0 w 1 w 2w n , that is, the first configuration in the accepting computation history of M for word w , as in the figure below.

5.16

MPCP匹配开始

Figure 5.16

MPCP Matching Start

在到目前为止获得的部分匹配的表示中,下面的单词由 $ q 0 w 1 w 2 ... w n #组成,而上面的单词仅包含#。为了获得匹配,我们需要扩展顶部的单词以匹配底部的单词。我们将提供更多的多米诺骨牌以实现这种扩展。这些额外的石子将导致机器M的下一个配置出现为低位字的扩展,强制模拟机器M的单步。

In this representation of the partial match obtained so far, the bottom word consists of $ q 0 w 1 w 2w n # , and the top word contains only # . To obtain a match, we must extend the top word to match the bottom word. We will provide additional dominoes to allow such an extension. These additional dominoes will cause the next configuration of machine M to appear as an extension of the bottom word, forcing a single-step simulation of machine M .

在第 2、3 和 4 部分中,我们将向P'添加多米诺骨牌,以执行模拟的主要部分。第 2 部分处理向右头部运动,第 3 部分处理向左头部运动,第 4 部分将处理不与头部相邻的磁带单元。

In Parts 2, 3, and 4 we will add dominoes to P' that perform the main part of the simulation. Part 2 handles head movements to the right, Part 3 head movements to the left, and Part 4 deals with tape cells that are not adjacent to the head.

第 2 部分。对于每个a , b Γ和每个q , r Q,其中q qreject

Part 2. For every a , b Γ and every q , r Q , where q q reject ,

第 3 部分.对于每个a , b Γ和每个q , r Q,其中q q拒绝

Part 3. For every a , b Γ and every q , r Q , where q q reject ,

第 4 部分.对于每个a Γ

Part 4. For every a Γ ,

我们现在将展示一个假设的示例来解释我们迄今为止所构建的内容。令Γ = { 0 , 1 , 2 , }。假设w是字0100并且机器M的初始状态是q 0。假设在状态q 0 中,读取符号0 后,转换函数告诉机器M进入状态q 7,将字符2写入磁带,并将磁头向右移动。换句话说,δ( q 0 , 0 ) = ( q 7 , 2 , R )。

We now show a hypothetical example to explain what we have built so far. Let Γ = { 0 , 1 , 2 , }. Suppose w is word 0100 and that the initial state of machine M is q 0 . Suppose that in state q 0 after reading symbol 0 , the transition function tells M to enter state q 7 , write character 2 to the tape , and move the head to the right. In other words, δ( q 0 , 0 ) = ( q 7 , 2 , R ).

第 1 部分将多米诺骨牌插入P'

Part 1 inserts a domino stone into P'

我们开始匹配

and we start matching

此外,第 2 部分将多米诺骨牌插入P'

Additionally, part 2 inserts a domino stone into P'

δ( q 0 , 0 ) = ( q 7 , 2 , R ),P'中的第 4 部分放置棋子

as δ( q 0 , 0 ) = ( q 7 , 2 , R ), and part 4 places stones in P'

因为012⊔是Γ的元素。与第 5 部分中的宝石一起使用,您可以将拟合范围扩展到

as 0 , 1 , 2 and are elements of Γ . Together with the stones from Part 5, this allows us to extend the matching to

因此,第 2、3 和 4 部分产生的多米诺骨牌允许通过在第一个配置之后添加第二个配置来扩展比赛。我们希望通过添加第三个配置,然后添加第四个,依此类推来继续此过程。为此,我们需要再添加一个多米诺骨牌来复制#

So the dominoes resulting from parts 2, 3, and 4 have allowed us to extend the match by adding a second configuration after the first. We want to continue this process by adding a third configuration, then a fourth, and so on. For this to happen, we need to add another domino implementing copy # .

第五部分

Part 5.

第一个石头将允许我们复制分隔配置的#符号。此外,第二块石头允许您在配置末尾添加一个空白符号,以模拟右侧无数个空符号,这些符号在保存配置时会被覆盖。

The first of these stones will allow us to copy the symbol # that separates configurations. Additionally, the second stone allows us to add an empty symbol to the end of the configuration to simulate an infinite number of empty symbols to the right that are overwritten when the configuration is saved.

继续我们的示例,假设在状态q 7中,读取1 后,机器M进入状态q 5,将0写入磁带,并将磁头向右移动。所以 δ( q 71 ) = ( q 5 , 0 , R )。所以在P'中我们会有一块石头

Continuing our example, suppose that in state q 7 after reading 1, machine M goes to state q 5 , writes 0 to the tape, and moves the head to the right. So δ( q 71 ) = ( q 5 , 0 , R ). In P' we will therefore have a stone

部分匹配扩展为

Partial fit extends to

然后假设在状态q 5 中,读取0 后,机器M进入状态q 9,写入磁带2并将磁头向左移动。换句话说,δ( q 5 , 0 ) = ( q 9 , 2 , L )。结果是多米诺骨牌

Next, suppose that in state q 5 after reading 0, machine M goes to state q 9 , writes 2 to the tape , and moves the head to the left. In other words, δ( q 5 , 0 ) = ( q 9 , 2 , L ). The result is dominoes

我们对第一个感兴趣,因为头部左侧的符号是0。之前的部分匹配扩展为

We are interested in the first one, because the symbol to the left of the head is 0 . The previous partial match extends to

请注意,当我们构建匹配时,我们需要模拟M对输入单词的操作。这个过程一直持续到M达到终止计算的状态。如果这是接受状态,我们将希望部分匹配的顶部“赶上”底部,以便匹配完成。我们可以通过添加额外的多米诺骨牌来实现这一点。

Note that as we construct the match, we need to simulate the action of M on the input word w . This process continues until M reaches a state that terminates the computation. If this is an accepting state, we want the upper part of the partial match to “catch up” with the lower part, so that the match is complete. We can achieve this by including additional dominoes.

第 6 部分.对于每个a Γ

Part 6. For every a Γ

此步骤的效果是在图灵机停止后向其添加“伪步骤”,其中头部“吃掉”相邻的符号,直到没有剩余。在我们的例子中,如果部分匹配直到机器停止在接受状态,那么

This step has the effect of adding "pseudo-steps" to the Turing machine that are executed after it has halted, as the head "eats" neighboring symbols until none remain. In our example, if a partial match occurs when the machine has halted in an accepting state, then

正是添加的棋子才使得比赛得以继续:

these added stones allow the matching to continue:

第 7 部分.最后,我们添加多米诺骨牌

Part 7. Finally, we add a domino stone

我们完成匹配:

and we finish the matching:

这样就完成了P'的构建。回想一下,P'是 MPCP 的一个实例,其中匹配模拟机器Mw的计算。为了完成证明,我们需要考虑到 MPCP 与 PCP 的不同之处在于,匹配必须从列表中的第一张多米诺骨牌开始。如果我们将P'视为 PCP 而不是 MPCP 的实例,那么无论M是否接受w ,它显然都有匹配。你能找到他们吗? (提示:它很短。)

This completes the construction of P' . Recall that P' is an instance of MPCP in which the matching simulates the computation of M for w . To complete the proof, we need to note that MPCP differs from PCP in that the matching must start with the first domino on the list. If we viewed P' as an instance of PCP rather than MPCP, then it clearly has a matching regardless of whether M accepts w . Can you find it? (Hint: It's very short.)

我们现在展示如何将P'转换为P ,这是仍然模拟w的机器M 的PCP 问题的一个实例。我们将为此使用一个技术技巧。这个想法是将重新开始的要求直接构建到问题实例中,以便自动满足它。因此,不再需要明确强制执行此要求。我们将引入一些额外的符号来实现这个想法。

We now show how to transform P' into P , an instance of the PCP problem that still simulates the machine M for w . We use a technical trick to do this. The idea is to build the requirement of starting from the first stone directly into the problem instance, so that it is automatically satisfied. As a result, we no longer need to enforce this requirement explicitly. We introduce some additional notation to implement this idea.

u = u 1 u 2 …u n为长度为n的任意单词。我们将*uu**u*定义为三个单词

Let u = u 1 u 2 …u n be any word of length n . We define *u , u* and *u* as three words

如您所见, * u在u中的每个字符之前添加符号 * ,u * 将其添加在u中的每个字符之后,而 * u * 在u中的每个字符之前和之后插入它。

As you can see, * u adds the * symbol before each character in u , u * adds it after each character in u , and * u * inserts it both before and after each character in u .

为了将P'转换为P(PCP 问题的一个实例),我们将执行以下操作。如果P'是一个集合

To transform P' into P , that is, an instance of the PCP problem, we perform the following operations. If P' is a set

那么设P是一个集合

then let P be a set

将 P 视为 PCP 的一个实例,我们可以看到唯一可能开始比赛的棋子是第一个棋子,

Considering P as an instance of PCP, we can see that the only stone that could potentially start the match is the first one,

因为它是唯一一块顶部和底部文字都以相同符号开头的宝石 - 特别是 *。除了强制比赛从第一颗棋子开始之外,哨子的存在不会影响可能的比赛,因为它们与原始符号交替出现。这些符号现在出现在均匀匹配的位置。石头

because it is the only tile where both the top and bottom words start with the same symbol – specifically, *. Other than forcing the match to start from the first tile, the presence of the whistle does not affect the possible matches, as they are arranged alternately with the original symbols. These symbols now appear in even-numbered match positions. The tile

此处出现是为了允许用附加*来补充顶部单词。

is present here to allow the top word to be supplemented with an additional*.

5.3

通过映射减少

5.3

Reduction by mapping

我们已经展示了如何使用归约技术来证明各种问题是不可判定的。在本节中,我们形式化了可归约性的概念。这将使我们能够以更复杂的方式使用归约,例如证明某些语言在图灵意义上以及在复杂性理论的框架中是不可识别的。

We have shown how reduction can be used to show that various problems are undecidable. In this section we formalize the notion of reducibility. This will allow us to use reduction in more sophisticated ways, for example to show that certain languages ​​are not Turing recognizable, and also within the framework of complexity theory.

将一个问题简化为另一个问题的概念可以通过多种方式正式定义。我们使用哪一种取决于应用程序。我们选择一种简单的可归约类型,称为映射归约2

The notion of reduction from one problem to another can be formally defined in many ways. Which one we use depends on the application. We choose a simple kind of reducibility called reduction by mapping 2 .

粗略地说,能够使用映射约简将问题A约简为问题B意味着存在一个可计算函数,可以将问题A的实例转换为问题B的实例。如果我们有这样一个称为归约的变换函数那么我们可以使用B的算法来求解A。基本原理是,问题A的任何实例都可以通过使用归约将其转换为B的实例,然后将该算法应用于B来解决。稍后我们将给出映射归约的准确定义。

Roughly speaking, the ability to reduce problem A to problem B using reduction by mapping means that there is a computable function that transforms instances of problem A into instances of problem B . If we have such a transforming function, called a reduction , then we can solve A using the algorithm for B . The rationale is that any instance of problem A can be solved by using reduction to transform it into instance B , and then applying the algorithm to B . We will give the exact definition of reduction by mapping in a moment.

可计算函数

Computable functions

图灵机通过从写在磁带上的函数参数开始并以其磁带输出停止来计算函数。

A Turing machine computes a function by starting with the function's argument written on tape and stopping with its output written on tape.

定义 5.17

Definition 5.17

如果某个图灵机M对于每个输入字w以存储在磁带上的字f ( w ) 停止,则函数f : Σ * Σ * 是一个可计算函数。

A function f : Σ * Σ * is computable if a certain Turing machine M for each input word w halts with the word f ( w ) written to the tape.

5.18

Example 5.18

所有常见的整数算术运算都是可计算函数。例如,我们可以构建一台机器,它接受输入m , n 并返回m + n ,即mn的总和。我们不会在这里给出细节,将它们作为练习。

All the usual integer arithmetic operations are computable functions. For example, we can build a machine that takes an input m , n and returns m + n , the sum of m and n . We will not go into the details here, but leave them as exercises.

5.19

Example 5.19

可计算函数可以对机器描述进行操作。例如,某些可计算函数接受输入w并返回图灵机M' 的描述,这样如果w = M 〉是图灵机M的编码,则M'是识别与M相同语言的机器永远不会尝试将磁头移动到磁带左端之外。函数f通过向机器M的描述添加多个状态来完成此任务。如果w不是有效的图灵机编码,则该函数返回 ε 。

Computable functions can operate on machine descriptions. For example, a certain computable function takes an input w and returns the description of a Turing machine M' such that if w = M is a Turing encoding of M , then M' is a machine recognizing the same language as M , which never tries to move the head past the left end of the tape. The function f accomplishes this task by adding multiple states to the description of M . The function returns ε if w is not a valid Turing encoding of M .

通过映射简化的正式定义

Formal definition of reduction by mapping

我们现在可以通过映射来定义缩减。像往常一样,我们将计算问题表示为语言。

We can now define reduction by mapping. As usual, we represent computational problems as languages.

定义 5.20

Definition 5.20

语言A可以通过映射到语言B来简化,我们将其写为Am B,如果存在一个可计算函数f : Σ * Σ * 使得对于每个w

A language A is reducible by a mapping to a language B , which we write as Am B , if there exists a computable function f : Σ * Σ *, such that for every w

w A f ( w ) B

w A f ( w ) B .

函数f称为从AB的约简。

The function f is called the reduction from A to B .

下图说明了通过映射进行缩减。

The figure below illustrates reduction by mapping.

5.21

函数fA约简为B

Figure 5.21

Function f reducing A to B

通过从AB 的映射进行归约提供了一种将有关A中的成员资格的问题转换为有关B中的成员资格的问题的方法。为了检查w是否 A,我们使用约简f将w转换为单词f ( w ) 并检查f ( w )是否 B 。术语“通过映射进行归约”来自提供执行归约方法的函数(映射)。

The reduction by mapping from A to B provides a way of transforming questions about membership in A into questions about membership in B . To check whether w A , we use the reduction f to transform w into a word f ( w ) and check whether f ( w ) B . The term reduction by mapping comes from the function (mapping) that provides a method to perform the reduction.

如果问题可以通过映射到另一个先前解决的问题来简化,那么我们就可以获得原始问题的解决方案。我们将在定理 5.22 中阐述这个想法。

If a problem is reducible by mapping to another, previously solved problem, then we can thereby obtain a solution to the original problem. We formulate this idea in Theorem 5.22.

定理5.22

Theorem 5.22

如果Am B并且B是可判定的,则A是可判定的。

If Am B and B is decidable, then A is decidable.

证明 MB 的解析机,设f为AB的约简如下描述AN决策机

Proof Let M be an arbitrating machine for B , and let f be a reduction of A to B . We describe the arbitrating machine N for A as follows.

N =“对于中的输入词:

N = "For input word in :

  1. 计算f ( w )。
  2. Calculate f ( w ).
  3. 对输入词f ( w )运行M并返回M " 返回的内容。
  4. Run M for input word f ( w ) and return what M " returns.

显然,如果w A,则f ( w ) B,因为f是AB的约简。因此,只要w A , M就接受f ( w ) 。因此,N按预期工作。

It is obvious that if w A , then f ( w ) B , since f is a reduction of A to B . Hence M accepts f ( w ) whenever w A . Thus N acts as expected.

定理 5.22 的以下推论是我们证明不可判定性的主要工具。

The following corollary of Theorem 5.22 was our main tool in proving undecidability.

结论 5.23

Motion 5.23

如果Am B并且A不可判定,则B不可判定。

If Am B and A is undecidable, then B is undecidable.

现在我们回到一些早期的证明,使用归约方法来获得通过映射归约的例子。

We now return to some of the earlier proofs using the reduction method to obtain examples of reduction by mapping.

5.24

Example 5.24

在定理 5.1 中,我们使用A TM的约简来证明HALT TM是不可判定的。这种减少展示了我们如何使用HALT TM解析器来构建A TM解析器。我们现在可以通过从A TM映射到HALT TM来演示减少。为此,我们需要提供一个可计算函数f,它接受输入M , w 并返回输出M' , w' ,其中

In Theorem 5.1 we used the reduction from A TM to prove that HALT TM is undecidable. This reduction showed how we could use the HALT TM resolving machine to construct the A TM resolving machine . We can now demonstrate the reduction by mapping from A TM to HALT TM . To do this we need to represent a computable function f that takes an input of the form M , w and returns an output M' , w' , where

M , w A TM当且仅当M' , w' HALT TM

M , w A TM if and only if M' , w' HALT TM .

下面的机器F计算缩减f

The following machine F computes the reduction f .

F = "对于输入词M , w

F = "For input word M , in :

  1. 构建以下机器M'
  2. Construct the following machine M' .

M' = 对于输入单词x

M' = For input word x :

  1. 对输入单词x运行M
  2. Run M for input word x .
  3. 如果M接受,则接受
  4. If M accepts, accept .
  5. 如果M拒绝,则进入循环。
  6. If M rejects, enter loop.
  7. 返回< M' , w' > ”。
  8. Return M' , w' ”.

这里有一个小问题,就是处理不符合预期格式的输入单词。当机器F根据“For input word Mw :”行的内容判断输入数据的形式不正确,因此输入字不属于A TM时,图灵机返回一个不属于HALT TM的单词。机器可以选择任何不属于HALT TM的字。一般来说,当描述计算从AB 的约简的图灵机时我们假设无效输入被映射到B之外的单词。

There is a slight problem here related to dealing with input words that do not conform to the expected format. When the machine F determines that the input is not in the proper form according to the line "For input word Mw :", and therefore the input word is not in A TM , then the Turing machine returns a word that is not in HALT TM . The machine can choose any word that is not in HALT TM . In general, when describing a Turing machine that computes a reduction from A to B , we assume that the invalid input is mapped to words outside B .

5.25

Example 5.25

定理 5.15 中波斯特对应问题的不可判定性证明包含两个映射简化。我们首先证明A TMm MPCP,然后证明 MPCP ≤ m PCP。在这两种情况下,我们都可以轻松获得约简函数,并证明它是通过映射进行的约简。正如我们将在练习 5.6 中展示的,映射关系的约简是传递的,因此这两个约简意味着A TMm PCP。

The proof of the undecidability of Post's correspondence problem in Theorem 5.15 involves two reductions by a mapping. In it, we show first that A TMm MPCP, and then that MPCP ≤ m PCP. In both cases, we can easily obtain the reduction function and show that it is a reduction by a mapping. As we will show in Exercise 5.6, the reduction by a mapping relation is transitive, so these two reductions imply that A TMm PCP.

5.26

Example 5.26

定理 5.4 的证明给出了从E TMEQ TM映射的约简。在这种情况下,f将M 转换为输出M , M 1 ,其中M 1是丢弃所有输入单词的机器。

The reduction by mapping from E TM to EQ TM is given in the proof of Theorem 5.4. In this case f transforms M to an output M , M 1 , where M 1 is a machine that discards all input words.

5.27

Example 5.27

定理 5.2 的证明显示了E TM的不可判定性,说明了我们在本节中定义的通过映射进行约简的正式概念与之前使用的可约性的非正式概念之间的区别。这个证明表明E TM是不可判定的,将语言A TM简化为它。让我们看看是否可以将这种约简变成通过映射的约简。

The proof of Theorem 5.2 showing the undecidability of E TM illustrates the difference between the formal notion of reduction by mapping that we defined in this section and the informal notion of reducibility used earlier. This proof shows that E TM is undecidable by reducing the language A TM to it . Let us see if we can transform this reduction into a reduction by mapping.

从原始的约简中,我们可以轻松构造一个函数f,它接受输入M , w 并产生输出M 1 ,其中M 1是证明中描述的图灵机。然而,M接受w当且仅当L ( M 1 ) 不为空时,因此f是从A TME TM的约简。虽然这证明了 E TM不可判定性,但由于可判定性不会通过应用补集而改变,因此它并没有通过从A TM映射到E TM来给我们带来约简本身。事实上,不存在这样的减少,如练习 5.5 所示。

From the original reduction, we can easily construct a function f that takes an input M , w and produces an output M 1 , where M 1 is the Turing machine described in the proof. However, M accepts w if and only if L ( M 1 ) is not empty, so f is a reduction from A TM to E TM . Although this proves the undecidability of E TM , since decidability does not change under the complement, it does not give us the mere reduction by mapping from A TM to E TM . In fact, such a reduction does not exist, as should be shown in Exercise 5.5.

当使用可还原性来证明某些语言的不可识别性时,通过映射到补码进行还原的敏感性是一个重要特征。我们还可以使用映射简化来证明某些问题是图灵无法识别的。以下定理类似于定理 5.22。

This sensitivity of reduction by mapping to complement is an important feature when using reducibility to prove that certain languages ​​are unrecognizable. We can also use reduction by mapping to prove that certain problems are not Turing recognizable. The following theorem is analogous to Theorem 5.22.

定理5.28

Theorem 5.28

如果Am B并且B是图灵可识别的,则A是图灵可识别的。

If Am B and B is Turing recognizable, then A is Turing recognizable.

证明与定理 5.22 相同,只是机器MN只需要识别而不需要解析彼此的语言。

The proof is identical to that of Theorem 5.22 except that the machines M and N only need to recognize, not resolve, each other's languages.

结论5.29

Motion 5.29

如果Am B并且A不是图灵可识别的,则B也不是图灵可识别的。

If Am B and A is not Turing recognizable, then B is not Turing recognizable.

在这个结论的典型应用中,我们假设AA TM,即语言A TM的补集。从推论 4.23 我们知道A TM不是图灵可识别的。根据映射约简的定义,Am BAm B的含义相同。为了证明B不可识别,我们可以证明A TMm B。我们还可以使用映射约简来证明有些问题既不是图灵可识别的,也不是图灵可共同识别的,如下面的定理所示。

In the typical application of this corollary, we assume that A is A TM , that is, the complement of A TM . By Corollary 4.23, we know that A TM is not Turing recognizable. By the definition of reduction by mapping, it follows that Am B is the same as Am B . To show that B is not recognizable, we can show that A TMm B . We can also use reduction by mapping to show that some problems are neither Turing recognizable nor Turing co-recognizable, as in the following theorem.

定理5.30

Theorem 5.30

EQ TM语言既不是图灵可识别的,也不是图灵共同识别的。

The EQ TM language is neither Turing recognizable nor Turing co-recognizable.

证明 首先,我们将证明EQ TM不是图灵可识别的。我们将通过证明A TM可简化为EQ TM来实现这一点。约简函数f 的工作原理如下。

Proof We first show that EQ TM is not Turing recognizable. We do this by showing that A TM is reducible to EQ TM . The reduction function f acts as follows.

F = "对于输入单词M , w ,其中M是图灵机,w是单词:

F = "For an input word M , w , where M is a Turing machine and w is a word:

  1. 构造两个图灵机M 1M 2

    M 1 = 对于任何输入:

    1. 拒绝
  2. Construct two Turing machines M 1 and M 2 :

    M 1 = For any input:

    1. Reject .

M 2 = 对于任何输入:

M 2 = For any input:

  1. w运行M。如果本机接受,则接受
  2. Run M for w . If this machine accepts, accept .
  1. 返回M 1 , M 2 ”。
  2. Return M 1 , M 2 ”.

在这种情况下,M 1不接受任何内容。如果M接受w,则M 2接受所有内容,因此两台机器不等效。相反,如果M不接受w,则M 2不接受任何内容,则M 1M 2等价。所以f将A TM简化为EQ TM

In this case M 1 accepts nothing. If M accepts w , then M 2 accepts everything, so the two machines are not equivalent. Conversely, if M does not accept w , then M 2 accepts nothing, and then M 1 and M 2 are equivalent. So f reduces A TM to EQ TM .

为了证明EQ TM不是图灵可识别的,我们将提出从A TM到EQ TM的补集的约简- 即EQ TM。这样我们就可以证明A TMm EQ TM。下面的G机计算约简函数g

To show that EQ TM is not Turing recognizable, we will show a reduction from A TM to the complement of EQ TM , namely EQ TM . In this way, we show that A TMm EQ TM . The following machine G computes the reduction function g .

G = "对于输入单词M , w ,其中M是图灵机,w是单词:

G = "For an input word M , w , where M is a Turing machine and w is a word:

  1. 构造两个图灵机M 1M 2

    M 1 = 对于任何输入:

    1. 接受
  2. Construct two Turing machines M 1 and M 2 .

    M 1 = For any input:

    1. Accept .

M 2 = 对于任何输入:

M 2 = For any input:

  1. w运行M
    1. 如果他接受,就接受
  2. Run M for w .
    1. If he accepts, accept .
  1. 返回M 1 , M 2 ”。
  2. Return M 1 , M 2 ”.

函数fg之间的唯一区别在于机器M 1。在函数f 中,机器M 1总是拒绝,而在函数g中,机器 M 1 总是接受。在函数fg 中,机器M接受w当且仅当M 2始终接受时。在函数g 中,机器M接受w当且仅当M 1M 2相等时。所以g是从A TMEQ TM的约简。

The only difference between the functions f and g lies in the machine M 1 . In function f , machine M 1 always rejects, and in function g always accepts. In both functions f and g , machine M accepts w if and only if M 2 always accepts. In function g , machine M accepts w if and only if M 1 and M 2 are equivalent. So g is a reduction from A TM to EQ TM .

练习

Exercises

5.1 证明EQ CFG语言是不可判定的。

5.1 Show that the language EQ CFG is undecidable.

5.2 证明EQ CFG语言在图灵意义上是可共同识别的。

5.2 Show that the language EQ CFG is Turing co-recognizable.

5.3 在以下帖子适宜性问题实例中查找匹配项。

5.3 Find a matching in the following instance of Post's correspondence problem.

5.4Am BB为正则语言;这是否意味着A是正则语言?为什么是或为什么不是?

5.4 Let Am B and B be a regular language; does this mean that A is a regular language? Why or why not?

A 5.5 证明A TM不能通过映射到E TM来简化。换句话说,证明不存在将A TM还原为E TM 的可计算函数。 (提示:使用您已经了解的有关A TME TM语言的隐式证明和事实。)

A 5.5 Prove that A TM is not reducible by a mapping to E TM . In other words, prove that there is no computable function that reduces A TM to E TM . (Hint: Use indirect proof and facts you already know about the languages ​​A TM and E TM .)

A 5.6 证明 ≤ m是传递关系。

A 5.6 Prove that ≤ m is a transitive relation.

A 5.7 证明如果A是图灵可判定的且A m A,则A是可判定的。

A 5.7 Prove that if A is Turing recognizable and A m A , then A is decidable.

A 5.8 在定理 5.15 的证明中,我们修改了图灵机M,使其永远不会尝试将磁头移动到磁带左端之外。假设我们没有对机器M进行此修改。修改 PCP 结构来处理这种情况。

A 5.8 In the proof of Theorem 5.15, we modified the Turing machine M so that it never tries to move the head past the left end of the tape. Suppose we did not make this modification to M . Modify the construction of PCP to handle this case.

任务

Tasks

5.9T = { M M是一个图灵机,只要它接受w },它就接受w R。证明语言T是不可判定的。

5.9 Let T = { M : M is a Turing machine accepting in R whenever it accepts in }. Prove that the language T is undecidable.

A 5.10考虑确定双磁带图灵机在运行某些输入 时是否会将非空符号写入第二磁带的问题。将这个问题表述为一种语言并证明它是不可判定的。

A 5.10 Consider the problem of determining whether a two-tape Turing machine will ever write a non-empty symbol to the second tape when it is run for some input w . State this problem in terms of a language and show that it is undecidable.

A 5.11 考虑确定双磁带图灵机在计算任何输入字期间是否将非空符号写入第二磁带的问题。将这个问题表述为一种语言并证明它是不可判定的。

A 5.11 Consider the problem of determining whether a two-tape Turing machine will ever write a non-empty symbol to the second tape during its computation for any input word. State this problem in terms of a language and show that it is undecidable.

5.12 考虑确定单带图灵机在计算任何输入字期间是否会写入空符号来代替非空符号的问题。将这个问题表述为一种语言并证明它是不可判定的。

5.12 Consider the problem of determining whether a single-tape Turing machine will ever store a null symbol in place of a non-null symbol during its computation of any input word. State this problem in terms of a language and show that it is undecidable.

5.13图灵机的 不可到达状态是指机器永远不会进入任何输入字的状态。考虑确定图灵机是否包含任何垃圾状态的问题。将这个问题表述为一种语言并证明它是不可判定的。

5.13 An unreachable state of a Turing machine is one that the machine will never enter for any input word. Consider the problem of determining whether a Turing machine contains any useless states. Formulate this problem in terms of a language and show that it is undecidable.

5.14考虑确定图灵机M在处理输入w 时是否会尝试将磁头移至左侧(当磁头位于磁带最左侧单元时) 的问题。将这个问题表述为一种语言并证明它是不可判定的。

5.14 Consider the problem of determining whether a Turing machine M, when processing input w, will ever try to move the head to the left when it is in the leftmost cell of the tape. State this problem in terms of a language and show that it is undecidable.

5.15 考虑确定图灵机M在处理单词w时是否会尝试将其头部从任何位置向左移动的问题。将这个问题表述为一种语言并证明它是可判定的。

5.15 Consider the problem of determining whether a Turing machine M , while processing word w, will ever attempt to move its head to the left from any position. State this problem in terms of a language and show that it is decidable.

5.16Γ = {0, 1, } 为我们在此问题中考虑的所有图灵机的磁带字母表。让我们定义繁忙的海狸函数BB : N 如下:对于每个k值,我们考虑所有具有k状态的图灵机,这些图灵机在用空磁带启动时会停止。令BB ( k ) 为这些机器写入磁带的 1 的最大数量。证明BB不是可计算函数。  

5.16 Let Γ = {0, 1, } be the tape alphabet for all the Turing machines we consider in this problem. Define the busy beaver function BB : N →  N as follows: for each value of k , consider all Turing machines with k states that halt when started with an empty tape. Let BB ( k ) be the maximum number of ones that any of these machines writes to the tape. Prove that BB is not a computable function. 

5.17 证明邮政通信问题在一元字母表Σ  = {1} 上是可判定的。

5.17 Prove that Post's correspondence problem is decidable over the unary alphabet Σ  = {1}.

5.18 证明邮政对应问题在二进制字母表Σ  = {0,1} 上是不可判定的。

5.18 Prove that the Post correspondence problem is not decidable over the binary alphabet Σ  = {0,1}.

5.19简单的邮政对应问题(SPCP)中,每对中顶部的单词与底部的单词具有相同的长度。证明 SPCP 是可判定的。

5.19 In the silly post correspondence problem ( SPCP), the top word in each pair has the same length as the bottom word. Prove that SPCP is decidable.

5.20 证明{1}*存在不可判定的子集。

5.20 Prove that there is an undecidable subset of the language {1}*.

5.21AMBIG CFG = { G G是一个二义 CFG 文法}。证明AMBIG CFG不可判定。 (提示:使用 PCP 的归约。给定 Post 的适用性问题的一个实例 P

5.21 Let AMBIG CFG = { G : G is an ambiguous CFG grammar}. Show that AMBIG CFG is undecidable. (Hint: Use the reduction with PCP. Given an instance P of the Post correspondence problem

使用以下产生式构造 CFG G语法

construct a CFG grammar G with the following productions

其中a 1、 ...k是新的终结符。证明这个减少是正确的。)

where a 1 , …, and k are new terminal symbols. Prove that this reduction is correct.)

5.22 证明A是图灵可识别的当且仅当Am A TM

5.22 Prove that A is Turing recognizable if and only if Am A TM .

5.23 证明A是可判定的当且仅当Am 0 * 1 *

5.23 Prove that A is decidable if and only if Am 0 * 1 * .

5.24J = { w:对于某些x A TM , w = 0 x,或对于某些y A TM ,w = 1 y }。证明JJ都不是图灵可识别的。

5.24 Let J = { w : either w = 0 x for some x A TM , or w = 1 y for some y A TM }. Show that neither J nor J are Turing recognizable.

5.25给出一个不可判定语言B 的例子,使得Bm B

5.25 Give an example of an undecidable language B such that Bm B .

5.26我们将 双头有限自动机 2DFA )定义为一种确定性有限状态机,配备两个双向只读头,从输入磁带的左端开始,可以在两个方向上独立移动。 2DFA 磁带是有限的,长度仅足以容纳输入数据和两个额外的空单元(一个在左端,一个在右端),以充当分隔符。 2DFA 通过转换到特殊的接受状态来接受输入。例如,2DFA 可以识别语言 { a n b n c n : n ≥ 0}。

5.26 A two-headed finite automaton ( 2DFA) is defined as a deterministic finite automaton with two bidirectional read-only heads that start at the left end of the input tape and can be moved independently in either direction. The 2DFA tape is finite and has a length just long enough to hold the input data plus two additional empty cells, one at the left end and the other at the right end, that act as delimiters. A 2DFA accepts input by transitioning to a special accepting state. For example, a 2DFA can recognize the language { a n b n c n : n ≥ 0}.

a.A 2DFA = { M , x M是 2DFA 并且M接受x }。证明2DFA可判定的。

a. Let A 2DFA = { M , x : M is a 2DFA and M accepts x }. Prove that A 2DFA is decidable.

b.E 2DFA = { M M是 2DFA 并且L ( M ) = Ø }。证明E 2DFA不可判定。

b. Let E 2DFA = { M : M is a 2DFA and L ( M ) = Ø }. Prove that E 2DFA is undecidable.

5.27我们定义 二维有限自动机 2DIM -DFA)如下。输入数据采用m × n矩形的形式,对于某些m ≥ 2。沿矩形边缘的字段包含符号# ,内部字段包含输入字母表Σ的符号。转移函数 δ : Q × ( Σ { # }) Q × { LR , U,  D } 表示下一个状态和头部的新位置(Left – left,Right – right,Up – up,下——下)。当机器进入指定的接受状态之一时,机器接受输入。如果输入尝试超出输入矩形或从未完成,则拒绝输入。如果两台这样的机器接受相同的矩形,那么它们是等效的。考虑确定其中两台机器是否等效的问题。将这个问题表述为一种语言并证明它是不可判定的。

5.27 A two-dimensional finite automaton ( 2DIM-DFA) is defined as follows. The input data is an m × n rectangle , for some m , ≥ 2. The fields along the edges of the rectangle contain the symbols # , and the inner fields contain the symbols of the input alphabet Σ . The transition function δ : Q × ( Σ { # }) Q × { LR , U,  D } indicates the next state and the new head position (Left, Right, Up, Down). The machine accepts the input when it enters one of the designated accepting states. It rejects the input if it tries to move outside the input rectangle or if it never terminates. Two such machines are equivalent if they accept the same rectangles. Consider the problem of determining whether two of these machines are equivalent. Formulate this problem as a language and show that it is undecidable.

A* 5.28 赖斯定理。令P为图灵机器语言的任何重要属性。证明确定给定图灵机是否具有属性P的问题是不可判定的。

A* 5.28 Rice's Theorem . Let P be any nontrivial property of the language of a Turing machine. Prove that the problem of determining whether a given Turing machine has the property P is undecidable.

更正式地写,令P是由满足以下两个条件的图灵机描述组成的语言。首先,P并不平凡——它包含一些但不是全部的图灵机描述。其次,P是图灵机器语言的一个属性——每当L ( M 1 ) = L ( M 2 ) 时,它就认为 M 1 P当且仅当M 2 P。在这种情况下,M 1M 2是任意图灵机。证明P是不可判定语言。

More formally, let P be a language of Turing machine descriptions that satisfies the following two conditions. First, P is nontrivial—it contains some, but not all, Turing machine descriptions. Second, P is a property of a Turing machine language—whenever L ( M 1 ) = L ( M 2 ), then M 1 P if and only if M 2 P . In this case, M 1 and M 2 are arbitrary Turing machines. Prove that P is an undecidable language.

5.29 证明问题 5.28 中提出的两个条件对于证明P不可判定是必要的。

5.29 Prove that both conditions given in Problem 5.28 are necessary to prove that P is undecidable.

5.30 使用问题 5.28 中提出的赖斯定理来证明以下每种语言的不可判定性。

5.30 Use Rice's theorem from Problem 5.28 to prove that each of the following languages ​​is undecidable.

A a. INFINITE TM = { <M> M是图灵机, L ( M )无限语言}。

And a. INFINITE TM = {M : M is a Turing machine and L ( M ) is an infinite language}.

b. { M M是图灵机且1011 L ( M )}。

b. { M : M is a Turing machine and 1011 L ( M )}.

c. ALL TM = { M M是图灵机且L ( M ) = Σ *}。

c. ALL TM = { M : M is a Turing machine and L ( M ) = Σ *}.

5.31

5.31 Let

对于任何自然数x。如果我们从整数x开始,逐一计算前面数字的函数f的值,我们将得到序列x , f ( x ), f ( f ( x )), ...。如果我们得到 1,我们就停止。例如,对于x = 17,我们得到序列 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1。广泛的计算机测试表明对于 1 和一个非常大的整数之间的任何起始点,我们都会得到一个以 1 结尾的序列。然而,寻找是否对于任何其他起始点我们都会得到以 1 结尾的序列这一问题的答案仍然没有解决。这称为 3 x + 1 问题。

for any natural number x . If we start with an integer x and evaluate the function f for the previous numbers one by one, we get the sequence x , f ( x ), f ( f ( x )), …. We stop if we ever get 1. For example, for x = 17 we get the sequence 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1. Extensive computer tests have shown that for any starting point between 1 and a very large integer we get the sequence ending in 1. However, the question of whether for any additional starting point we get the sequence ending in 1 is still unsolved. This is called the 3x + 1 problem.

假设A TM可由某个图灵机H判定。使用H来描述能够解决 3 x + 1 问题的图灵机。

Suppose A TM is decidable by some Turing machine H . Use H to describe a Turing machine that will be able to decide the 3 x + 1 problem.

5.32 证明下列语言是不可判定的。

5.32 Prove that the following languages ​​are undecidable.

a. OVERLAP CFG = { G , H GH是 CFG 文法,使得L ( G ) L ( H ) Ø }。 (提示:使用练习 5.21 中的提示。)

a. OVERLAP CFG = { G , H : G and H are CFGs such that L ( G ) L ( H ) Ø }. (Hint: Use the hint from Exercise 5.21.)

b. PREFIX-FREE CFG = { G G是 CFG 语法,其中L ( G ) 是前缀语言}。

b. PREFIX-FREE CFG = { G : G is a CFG grammar for which L ( G ) is a prefix language}.

5.33考虑确定给定 PDA 是否接受 { ww Î  {0,1} * } 形式的某个单词的问题。使用计算历史方法表明该问题是不可判定的。

5.33 Consider the problem of determining whether a given PDA accepts a word of the form { ww Î  {0,1} * }. Use the computation history method to show that this problem is undecidable.

5.34X = { M , w M是单磁带图灵机,它从不修改包含输入词w的磁带部分}。X是可判定的吗?证明你的答案。

5.34 Let X = { M , w : M is a single-tape Turing machine that never modifies the part of the tape containing the input word w }. Is X decidable? Prove your answer.

5.35如果变量 A 出现在ε G某个词的每个推导中,则我们说属于 CFG 语法G的 变量A必需的。令NECESSARY CFG = { G , A : A是G中的必需变量}。

5.35 We say that a variable A belonging to a CFG grammar G is required if it appears in every derivation of some word w G . Let NECESSARY CFG = { G , A : A is a required variable in G }.

a. 证明NECESSARY CFG是图灵可识别的。

a. Show that NECESSARY CFG is Turing recognizable.

b. 证明NECESSARY CFG是不可判定的。

b. Prove that NECESSARY CFG is undecidable.

*5.36如果在不更改生成语言的情况下无法删除 CFG 语法的任何产生式, 我们就说 CFG 语法是最小的。设MIN CFG = { G G是最小 CFG 语法}。

*5.36 We say that a CFG grammar is minimal if none of its productions can be removed without changing the generated language. Let MIN CFG = { G : G be a minimal CFG grammar}.

a. 证明MIN CFG是图灵可识别的。

a. Show that MIN CFG is Turing recognizable.

b. 证明MIN CFG不可判定。

b. Prove that MIN CFG is undecidable.

精选解决方案

Selected solutions

5.5 假设通过减少f , A TMm E TM。根据映射归约的定义,通过相同的归约函数f得出A TMm E TM。然而,E TM是图灵可识别的(参见练习 4.5 的解决方案),而A TM不是图灵可识别的,这与定理 5.28 矛盾。

5.5 Suppose that A TMm E TM by the reduction f . By the definition of reduction by a mapping, it follows that A TMm E TM by the same reduction function f . However, E TM is Turing recognizable (see the solution to Exercise 4.5), and A TM is not Turing recognizable, which gives a contradiction with Theorem 5.28.

5.6 假设Am BBm C。则存在可计算函数fg,使得x A f ( x ) By B g ( y ) C。考虑函数h ( x ) = g ( f ( x )) 的组合。我们可以构建一个计算h的图灵机,如下所示:首先,我们模拟一个对输入词x计算f的图灵机(这样的机器存在,因为我们假设f是可计算的) ,我们将这台机器的输出称为y。然后,我们模拟图灵机计算输入词y的函数g。输出为h ( x ) = g ( f ( x ))。因此h是一个可计算函数。此外,x A h ( x ) C。因此,通过约简函数h , AmC

5.6 Suppose that Am B and Bm C . Then there exist computable functions f and g such that x A f ( x ) B and y B g ( y ) C . Consider the composition of functions h ( x ) = g ( f ( x )). We can construct a Turing machine computing h as follows: first, we simulate a Turing machine computing f (such a machine exists, since we have assumed that f is computable) for input word x and call the output of this machine y . Next, we simulate a Turing machine computing the function g for input word y . The output is h ( x ) = g ( f ( x )). Hence h is a computable function. Moreover, x A h ( x ) C . Hence Am C by the reduction function h .

5.7 假设Am A。则Am A通过映射进行相同的简化。由于A是图灵可识别的,因此从定理 5.28 可以得出A也是图灵可识别的,然后从定理 4.22 可以得出A是可判定的。

5.7 Suppose Am A . Then Am A by the same reduction by mapping. Since A is Turing recognizable, it follows from Theorem 5.28 that A is also Turing recognizable, and then it follows from Theorem 4.22 that A is decidable.

5.8 我们需要处理磁头位于最左边磁带单元上方并尝试向左移动的情况。为了实现这一点,我们添加多米诺骨牌

5.8 We need to handle the case when the head is over the leftmost tape cell and tries to move to the left. To do this, we add dominoes

对于每个qr Qab Γ,其中 δ( q , a ) = ( r , b , L )。此外,我们用骰子替换第一张多米诺骨牌

for each q , r Q and a , b Γ , where δ( q , a ) = ( r , b , L ). Additionally, we replace the first domino with a die

处理头部在第一次(初始)移动中尝试向左移动的情况。

to handle the case when the head tries to move to the left on the first (initial) move.

5.10B = { M , w M是双磁带图灵机,在处理输入w时将非空符号写入第二磁带}。我们将证明A TM简化为B。为了矛盾起见,假设图灵机R解析了B。然后我们将使用R构建机器S来解析语言A TM

5.10 Let B = { M , w : M is a two-tape Turing machine that writes a nonempty symbol to the second tape while processing the input w }. We show that A TM reduces to B . For the sake of contradiction, suppose that a Turing machine R decides B . We then construct a machine S that uses R to decide the language A TM .

S = "对于输入词M , w

S = "For input word M , in :

1.M构造如下两带机T。

1. Use M to construct the following two-tape machine T .

T = 对于输入词x

T = For input word x :

1.使用第一个磁带 模拟输入字x的 M。

1. Simulate M for input word x using the first tape.

2. 如果模拟显示M接受,则将非空符号写入第二个磁带。

2. If the simulation shows that M accepts, write a non-empty symbol to the second tape.

2.对数据< T , w > 运行R,以确定输入字w的T是否将非空符号写入其第二个磁带。

2. Run R on the data T , w to determine whether T writes a nonempty symbol to its second tape for input word w .

3. 如果R接受,则意味着M接受w,因此接受。否则,丢弃。”

3. If R accepts, it means that M accepts at , therefore accept . Otherwise reject ”.

5.11C = { M M是双磁带图灵机,在运行某些输入后将非空符号写入其第二磁带}。我们将证明A TM简化为C。为了获得矛盾,我们假设某个图灵机R可以解析C。我们将使用R构建机器S来解析A TM

5.11 Let C = { M : M is a two-tape Turing machine that writes a nonempty symbol to its second tape when it is run for some input}. We will show that A TM reduces to C . For contradiction, suppose that some Turing machine R decides C . We will construct a machine S that uses R to decide A TM .

S = "对于输入词M , w

S = "For input word M , in :

1. 使用M构造以下 中的两带图灵T。

1. Use M to construct the following two-tape Turing machine T in .

T w = 对于任何输入:

T w = For any input:

1.使用第一个磁带 模拟输入字w 的M。

1. Simulate M for input word w , using the first tape.

2. 如果模拟显示M接受,则将非空符号写入第二个磁带。

2. If the simulation shows that M accepts, write a non-empty symbol to the second tape.

2.对数据T w 运行R以确定T w是否会将非空符号写入其第二个磁带。

2. Run R on data T w to determine whether T w ever writes a nonempty symbol to its second tape.

3. 如果R接受,则意味着M接受w,因此接受。否则,丢弃。”

3. If R accepts, it means that M accepts at , therefore accept . Otherwise reject ”.

5.28 为了获得矛盾,假设P是满足这两个属性的可判定语言,并令R P是确定P的图灵机。我们将展示如何通过构造机器S使用R P解析语言A TM。首先,令 T 0为拒绝所有单词的图灵机,因此我们有L ( T 0 ) = Ø。我们可以不失一般性地假设T 0 P ,因为在T 0 P的情况下,我们可以使用P代替P来进一步进行。由于P是非平凡的,因此存在图灵机T使得T P。我们将设计S来解析语言A TM ,利用R P区分T 0T的能力。

5.28 To obtain a contradiction, suppose P is a decidable language satisfying both properties, and let R P be a Turing machine that decides P . We show how to decide the language A TM using R P by constructing a machine S . First, let T 0 be a Turing machine that rejects all words, so we have L ( T 0 ) = Ø . We can assume without loss of generality that T 0 P , since in the case that T 0 P , we could proceed by using P instead of P . Since P is nontrivial, there exists a Turing machine T such that T P . We design S that decides the language A TM using R P 's ability to distinguish T 0 from T .

S = "对于输入词M , w

S = "For input word M , in :

1. 使用M i w构造以下机器M w

1. Use M and w to construct the following machine M w .

M w = 对于输入词x

M w = For input word x :

1.对中的输入词 模拟M。如果它停止并拒绝,则丢弃。如果他接受,请转至步骤 2。

1. Simulate M for input word w . If it stops and rejects, reject . If it accepts, go to step 2.

2.针对输入词x 模拟T。如果他接受,就接受

2. Simulate T for input word x . If it accepts, accept .

2. 使用R P机判断是否M w P。如果是,请接受。如果否,则拒绝

2. Use the machine R P to determine whether M w P . If YES, accept . If NO, reject ”.

如果M接受w ,则机器M w模拟T。因此,如果M接受w,则L ( M w ) 等于L ( T ) ,否则等于Ø。因此,当且仅当M接受w时,< M w > P。

A machine M w simulates T if M accepts w . Therefore L ( M w ) equals L ( T ) if M accepts w , and Ø otherwise. Therefore M w P if and only if M accepts w .

5.30 ( a ) INFINITE TM是一种图灵机描述语言,满足赖斯定理的两个条件。首先,它并不平凡,因为一些图灵机有无限的语言,而另一些则没有。其次,机器与它​​的从属关系仅取决于它的语言。如果两台图灵机识别相同的语言,那么要么两者的描述都属于INFINITE TM,要么都不属于 INFINITE TM 。因此,赖斯定理意味着INFINITE TM是不可判定的。

5.30 ( a ) INFINITE TM is a language of Turing machine descriptions that satisfies both conditions of Rice's theorem. First, it is nontrivial, since some Turing machines have infinite languages ​​and others do not. Second, a machine's membership in it depends only on its language. If two Turing machines recognize the same language, then either the descriptions of both belong to INFINITE TM , or neither belongs to it. So it follows from Rice's theorem that INFINITE TM is undecidable.

6

可计算性理论的高级主题

6

Advanced Topics in Computability Theory

在本章中,我们将探讨计算理论的四个更高级的领域:(1)递归定理,(2)逻辑理论,(3)图灵约简,以及(4)描述复杂性。除了逻辑理论部分末尾的递归定理的应用之外,每个部分讨论的主题本质上是独立于其他主题的。本书的第三部分不依赖于本章中包含的任何信息。

In this chapter, we will explore four more advanced areas of computational theory: (1) the recursion theorem, (2) logical theories, (3) Turing reduction, and (4) description complexity. The topic discussed in each section is essentially independent of the others, with the exception of the application of the recursion theorem at the end of the section on logical theories. Part III of this book does not rely on any information in this chapter.

6.1

递归定理

6.1

Recursion Theorem

递归定理是一项数学成就,在可计算性理论的高级工作中发挥着重要作用。它与数理逻辑、自我复制机器理论,甚至计算机病毒都有联系。作为递归定理的介绍,我们将提出一个在研究生活时出现的悖论。他正在考虑建造能够自我复制的机器的可能性。这个悖论可以总结如下。

The recursion theorem is a mathematical achievement that plays an important role in advanced work in computability theory. It has connections with mathematical logic, the theory of self-replicating machines, and even with computer viruses. As an introduction to the recursion theorem, we will present a paradox that arises in the study of life. It considers the possibility of building machines that would be able to construct replicas of themselves. The paradox can be summarized as follows.

  1. 生物是机器。
  2. Living things are machines.
  3. 生物可以自我复制。
  4. Living things can replicate on their own.
  5. 机器无法自我复制。
  6. Machines cannot replicate themselves.

陈述1是现代生物学的教条。我们相信生物体以机械方式运作。陈述2是显而易见的。自我复制的能力是每个生物物种的基本特征。关于陈述3,我们使用以下推理来表明机器无法自我复制。考虑一台构建其他机器的机器,例如生产汽车的自动化工厂。原材料从一侧进入,生产机器人执行一组指令,然后成品车辆从另一侧出来。

Statement 1 is a dogma of modern biology. We believe that organisms act mechanistically. Statement 2 is obvious. The ability to self-replicate is a fundamental characteristic of every biological species. As for Statement 3, we use the following reasoning to show that machines cannot self-replicate. Consider a machine that builds other machines, such as an automated factory that produces cars. Raw materials enter at one end, manufacturing robots execute a set of instructions, and finished vehicles exit at the other end.

我们认为,工厂必须比它生产的汽车更复杂,因为设计工厂比设计汽车更困难。这种说法一定是正确的,因为工厂本身必须包含汽车的设计以及生产汽车的所有机器人的设计。同样的推理适用于构建机器B的任何机器AA必须比B更复杂。然而,机器不能比机器本身更复杂。因此,没有机器能够自我构建,因此自我复制是不可能的。

We claim that a factory must be more complex than the cars it makes, in the sense that designing a factory is harder than designing a car. This claim must be true, since the factory itself must contain the design for the car and the designs for all the robots that make them. The same reasoning applies to any machine A that builds machine B : A must be more complex than B . But a machine cannot be more complex than itself. Consequently, no machine can build itself, and therefore self-replication is impossible.

我们怎样才能解决这个悖论呢?答案很简单:陈述 3 是错误的。建造能够自我复制的机器是可能的。递归定理展示了如何做到这一点。

How can we resolve this paradox? The answer is simple: Statement 3 is false. It is possible to build machines that can reproduce themselves. The recursion theorem shows how this can be done.

自参考

Self-reference

我们将从构建一台忽略输入并打印其描述副本的图灵机开始。我们将这台机器称为SELF。为了能够描述SELF,我们需要以下引理。

We begin by building a Turing machine that ignores its input and prints out a copy of its description. We will call this machine SELF . To describe SELF , we need the following lemma.

引理6.1

Lemma 6.1

存在一个可计算函数q : Σ * Σ *,如果w是任意单词,则q ( w ) 是图灵机P w的描述,该图灵机打印单词w然后停止。

There is a computable function q : Σ * Σ * such that if w is any word, then q ( w ) is the description of a Turing machine P w that outputs word w and then halts.

证明 一旦我们理解了这个引理的命题,证明就变得简单了。显然,我们可以采用任何单词w并基于它构造一个图灵机,该图灵机会将w内置到其结构中,因此在运行时,机器可以简单地输出w。下面的图灵机Q计算q ( w )。

Proof Once we understand the thesis of this lemma, the proof becomes straightforward. It is obvious that we can take any word w and construct a Turing machine from it that has w built into its construction, so that when run, the machine can simply output w . The following Turing machine Q computes q ( w ).

Q =“对于中的输入词:

Q = "For input word in :

  1. 构造以下图灵机P。

    P w = 对于任何输入:

    1. 擦除输入数据。
    2. 保存磁带。
    3. 停止。
  2. Construct the following Turing machine P in .

    P w = For any input:

    1. Erase input.
    2. Save to tape.
    3. Stop.
  3. 返回P in ”。
  4. Return P into ”.

SELF图灵机由两部分组成:A和 B。我们可以将A和 B视为两个独立的过程,其组合操作会创建SELF。我们希望SELF输出SELF = AB

A Turing machine SELF consists of two parts, A and  B . We can think of A and  B as two separate procedures whose combined operation constitutes SELF . We want SELF to output SELF = AB .

A部分首先执行,工作完成后,控制权转移到B 部分。 A的角色是打印机器B的描述,相反, B的任务是打印机器A的描述。结果是所需的SELF描述。这些任务相似,但执行方式不同。首先,我们将向您展示如何获得A部分。

Part A executes first and after finishing its work passes control to B . The role of A is to print the description of machine B and conversely, the task of B is to print the description of machine A . The result is the desired description SELF . These tasks are similar but are implemented in different ways. First we will show how to obtain part A .

为了构建A,我们将使用机器P B ,由函数q ( B 〉 ) 描述,这是将函数q应用于B 的结果。所以A部分是一个图灵机打印描述<B> 然而,我们对A的描述取决于对B的描述。因此,在构造出B之前,我们无法完成对 A 的描述。

To construct A , we use a machine P B , described by a function q ( B ), which is the result of applying the function q to B . So part A is a Turing machine that prints the description B . However, our description of A depends on having a description of B . So we cannot complete the description of A until we construct B .

现在让我们继续B部分。使用q ( A 〉 ) 定义B可能很诱人,但这没有意义!这样做会由A定义机器B ,而 A 又由B定义。这将是相同对象对对象的循环定义,这是不可接受的。相反,我们将定义B使用不同的策略打印 A 的描述:B根据A返回的输出计算A。

Now let's look at the B part . It might be tempting to define B using q ( A ), but that wouldn't make sense! That would define the machine B by A , which in turn is defined by B . That would be a cyclic definition of objects by the same objects, which is not allowed. Instead, let's define B to print out the description of A using a different strategy: B would compute A based on the output returned by A .

我们将A 定义为q ( B )。现在来了最困难的部分:如果B可以得到B ,他可以将函数q应用于这个单词并得到A 。但是B从哪里可以得到B 这个词呢?A完成表演后,它被留在了磁带上!因此,B只需读带即可得到〈B〉然后B计算q ( B ) = A ,将A和 B合并到一台机器中,并在磁带上打印其描述AB = SELF 。综上,我们得到:

We defined A to be q ( B ). Now comes the hard part: if B can get B , she can apply the function q to that word and get A . But where did B get the word B ? It was left on the tape after A finished! So B just needs to read the tape to get B . Then B computes q ( B ) = A , combines A and  B into a single machine, and prints its description AB = SELF on the tape. To summarize, we have:

A = P B ,并且

A = P B , and

B = "对于输入词M ,其中M是图灵机的一个片段:

B = "For input word M , where M is a fragment of the Turing machine:

  1. 计算q ( M )。
  2. Calculate q ( M ).
  3. 将结果与<M>结合起来创建图灵的完整描述。
  4. Combine the result with M to form a complete description of the Turing machine.
  5. 打印这台机器的描述并完成。”
  6. Print a description of this machine and finish."

至此SELF的构建就完成了,其示意图如下图所示。

This completes the SELF construction , the schematic diagram of which is shown in the figure below.

6.2图灵机打印其描述的SELF

Figure 6.2 SELF

diagram of a Turing machine printing its description

如果我们现在运行SELF,我们可以注意到以下行为。

If we now run SELF , we can notice the following behavior.

  1. 首先,机器A启动并纸带上打印〈B〉
  2. First, machine A starts up and prints B on the tape.
  3. 机器B启动。他读了磁带并在上面找到了自己的输入<B>
  4. Machine B starts up . It reads the tape and finds its input on it, which is B .
  5. B计算q ( B ) = A 并将该结果与单词B 组合成图灵机的完整描述SELF
  6. B computes q ( B ) = A and combines this result with the word B into a complete description of the Turing machine, SELF .
  7. B打印该描述并停止。
  8. B prints this description and stops.

我们可以轻松地用任何编程语言实现此构造,从而生成一个返回自身副本的程序。我们甚至可以用简单的语言来做到这一点。假设我们想要创建一个句子,指示读者打印同一个句子的副本。所以我们可以说,例如:

We can easily implement this construct in any programming language, giving us a program that returns a copy of itself. We can even do this in plain language. Suppose we want to create a sentence that tells the reader to print out a copy of the same sentence. So we can say, for example:

打印这句话。

Print this sentence.

这句话具有所需的含义,因为它告诉读者打印同一句话的副本。然而,它没有明显的翻译成编程语言,因为“to”这个词,意思是自我引用,通常在编程语言中没有对应的词。然而,这种自我指涉对于形成我们的句子来说并不是必需的。让我们考虑以下替代方案。

This sentence has the desired meaning of telling the reader to print out a copy of the same sentence. However, it has no obvious translation into a programming language, since the word "it," which means self-reference, usually has no equivalent in programming languages. However, such self-reference is not necessary to construct our sentence. Consider the following alternative.

将以下句子打印两份,第二份放在引号中:

Print two copies of the following sentence, the second one enclosed in quotation marks:

“将以下句子打印两份,第二份放在引号中:”

"Print two copies of the following sentence, the second in quotation marks:"

在这句话中,自引用被替换为类似于构建SELF图灵机所使用的结构。该结构的B部分是元素:

In this sentence, the self-reference is replaced by a construction analogous to that used in constructing the Turing machine SELF . Part B of this construction is the term:

将以下内容打印两份,第二份用引号引起来:

Print two copies of the following, the second in quotes:

A部分是相同的,但用引号引起来。它将B的副本传递给B部分,以便B可以处理该副本,就像 TM 一样。

Part A is the same, but enclosed in quotation marks. It provides a copy of B to part B , so that B can process that copy, just as TM does.

递归定理提供了在任何编程语言中实现自引用的能力。这允许任何程序引用它自己的描述,正如我们将看到的,它具有特定的应用程序。在我们开始之前,让我们先陈述一下递归定理本身。它扩展了我们在构建SELF时使用的技术,以便程序可以获得自己的描述,然后继续使用手头的描述执行计算,而不是仅仅将其写出来。

The recursion theorem provides the ability to implement self-referencing in any programming language. This allows any program to refer to its own description, which, as we will see, has some specific applications. Before we get to that, let's state the recursion theorem itself. It extends the technique we used in the SELF construction so that a program can obtain its own description, and then continue its computations with its description at hand, rather than just writing it out.

定理6.3

Theorem 6.3

递归 定理 T为计算函数t的图灵机 Σ * × Σ *Σ *。有一台图灵机R计算函数r : Σ *Σ * 使得对于每个w

Recursion  Theorem  Let T be a Turing machine computing the function t : Σ * × Σ *Σ *. There exists a Turing machine R computing the function r : Σ *Σ *, such that for every w ,

r ( w ) = t ( R , w )。

r ( w ) = t ( R , w ).

这个定理的措辞看似相当“技术”,但实际上代表了一个非常简单的想法。要创建一个可以获取自己的描述,然后继续使用该描述进行计算的图灵机,我们只需要构建一个机器,在定理中称为T,它接收机器的描述作为附加输入。然后,递归定理产生一个新机器R,其工作方式与T完备相同,但自动提供描述R。

The statement of this theorem seems rather "technical," but it actually represents a very simple idea. To construct a Turing machine that can obtain a description of itself, and then continue computing with that description at its disposal, we need only construct a machine, named in the theorem T , that receives the description of the machine as additional input. The recursion theorem then produces a new machine R that acts exactly like T , but with the description R automatically supplied to it .

证明 证明类似于SELF机器的设计。分三部分A BT构建图灵机R,其中T是定理假设中给出的机器; R机的运行图如下图所示。

Proof The proof is analogous to the construction of the SELF machine . We will construct the Turing machine R in three parts A , B and T , where T is the machine given in the assumption of the theorem; the scheme of operation of the machine R is shown in the figure below.

6.4 R

机示意图

Figure 6.4

Schematic diagram of the R machine

在这种情况下,Aq ( <BT> )描述图灵P <BT>。为了保留输入单词,我们将更改函数q,以便P BT 在磁带上先前存在的任何单词之后打印其输出。当您启动A 时,磁带包含BT

In this case A is a Turing machine P BT described by q ( BT ). To store the input word w , we modify the function q so that P BT writes its output after any word that was previously on the tape. After A is run , the tape contains w BT .

同样,B是一个解析磁带内容并应用于该内容的过程。结果是<A> 然后B将ABT组合成一台机器,获得其描述ABT = R 。最后,它将这个描述与单词w一起编码,将生成的单词< R , w >放在磁带上,并将控制权传递给机器T。

Again, B is a procedure that analyzes the contents of the tape and applies it to those contents. The result is A . B then combines A , B , and T into a single machine, obtaining its description ABT = R . Finally, it encodes this description together with the word w , puts the resulting word R , w on the tape, and passes control to machine T .

使用递归定理

Using the Recursion Theorem

递归定理指出,图灵机可以获得自己的描述并使用它来执行计算。乍一看,这种可能性似乎只对琐碎的任务有用,例如建造一台可以打印自身副本的机器。然而,正如我们将要展示的,递归定理是解决算法理论中某些问题的有用工具。

The recursion theorem states that a Turing machine can obtain a description of itself and use it to perform computations. At first glance, this possibility seems useful only for trivial tasks, such as building a machine that prints out a copy of itself. However, as we will show, the recursion theorem is a useful tool for solving certain problems in algorithm theory.

我们可以使用递归定理通过以下方式创建图灵机算法。当我们创建机器M时,我们可以在算法M的非正式描述中包含短语“获取你自己的描述〈M〉。一旦M有了自己的描述,它就可以像使用任何其他计算值一样使用它。例如,M可以像SELF机器一样简单地打印M 〉 ,但它也可以计算M 中的状态数,甚至可以模拟M 。为了说明这种方法,我们将使用递归定理来描述SELF机。

We can use the recursion theorem to construct algorithms for Turing machines in the following way. When we construct a machine M , we can include the phrase "obtain your own description of M " in an informal description of the algorithm M . Once M has its own description , it can use it just as it would any other computed value. For example, M could simply print out M , as in the case of the SELF machine , but it could also count the number of states in M , or even simulate M 〉 . To illustrate this method, we will use the recursion theorem to describe the SELF machine .

SELF =“对于任何输入:

SELF = "For any input:

  1. 通过递归定理得到你自己的描述〈SELF〉
  2. Obtain your own description 〈SELF by the recursion theorem .
  3. 打印自我
  4. Print SELF ”.

递归定理展示了如何实现“获取您自己的描述”结构。为了构建SELF机器,我们首先创建以下T机器。

The recursion theorem shows how to implement the “get your own description” construction. To build the SELF machine , we first create the following machine T .

T = "对于输入词M , w

T = "For input word M , in :

  1. 打印〈M〉保留
  2. Print M and keep it."

机器T接收机器M的描述和单词w作为输入,并打印M的描述。然后,递归定理展示了如何获得机器R,对于输入单词w,它的作用就像T对于输入单词R , w 的作用一样。因此,R将打印描述R - 正是我们想要从SELF机器获得的内容。

A machine T receives as input a description of a machine M and a word w , and prints out the description of M . Then the recursion theorem shows how to obtain a machine R that, for input word w , will behave as T does for input word R , w . So R will print out a description of R – exactly what we wanted from a machine SELF .

用法

Usage

计算机病毒是一种旨在将自身传播到各种计算机的程序。这个简洁的名字表明它与生物病毒有很多共同点。当计算机病毒作为一段代码保持隔离时,它们就处于非活动状态。然而,一旦它们在给定的计算机上启动并“感染”它,它们就会变得活跃并将自身的副本传输到其他可用的计算机。多种媒体可用于传播病毒,包括互联网和可移动驱动器。为了完成其自我复制的主要任务,病毒可能包含递归定理证明中描述的结构。

A computer virus is a program that is designed to self-replicate on different computers. This neat name suggests that it has much in common with biological viruses. Computer viruses are inactive when they stand alone, as a piece of code. However, once they are run on a computer, "infecting" it, they become active and send copies of themselves to other accessible machines. A variety of media can be used to transmit viruses, including the Internet and removable disks. To perform its basic task of self-replication, a virus may contain a construct described in the proof of the recursion theorem.

我们现在考虑三个定理,其证明使用递归定理。额外的应用将出现在第 6.2 节中定理 6.17 的证明中。

We now consider three theorems whose proofs use the recursion theorem. An additional application will appear in the proof of Theorem 6.17 in Section 6.2.

首先,我们回到ATM语言不可判定性的证明。回想一下,我们之前在定理 4.11 中使用康托尔对角化方法证明了这一点。递归定理使我们能够提出一个新的、更简单的证明。

We first return to the proof of the undecidability of the language A TM . Recall that we previously proved it in Theorem 4.11 using Cantor's diagonal method. The recursion theorem allows us to provide a new and simpler proof.

定理6.5

Theorem 6.5

而且TM是不可判定的。

And TM is undecidable.

证明 让我们假设图灵机H解析语言A TM能够产生矛盾。以下机器B。

Proof Suppose a Turing machine H resolves the language A TM , so as to be able to achieve a contradiction. We construct the following machine B .

B =“对于输入单词

B = "For input word in :

  1. 通过递归定理,得到你自己的<B>描述
  2. By the recursion theorem, obtain your own description of B .
  3. 对输入单词B , w 运行H
  4. Run H for input word B , w .
  5. 对结果H采取相反的行动。换句话说,如果H拒绝输入,则接受;如果H接受,则拒绝。”
  6. Do the opposite of the result of H . In other words, accept if H rejects the input, and reject if H accepts."

对输入字运行B会产生与 H 指示的相反效果。因此,H不能是A TM解析器。准备好!

Running B on an input word produces the opposite action to that indicated by H. Hence, H cannot be an A TM resolving machine . Done!

下一个关于最小图灵机的定理是递归定理的另一个应用。

The next theorem, concerning minimal Turing machines, is another application of the recursion theorem.

定义 6.6

Definition 6.6

如果M是图灵机,则机器M 的描述长度<M>属于描述M 的单词的符号数量。如果没有对M具有更短描述的等效图灵机,我们就说M是最小的。让

If M is a Turing machine, the length of the description M of M is the number of symbols that belong to a word describing M . We say that M is minimal if there is no equivalent Turing machine for M with a shorter description. Let

MIN TM = { M : M是最小 TM}。

MIN TM = { M : M is the minimal TM}.

定理6.7

Theorem 6.7

MIN TM语言不可被图灵识别。

The MIN TM language is not Turing-recognizable.

证明 我们假设某个枚举器E枚举了语言MIN TM,这将导致矛盾。我们将构建以下图灵机C。

Proof We will assume that some enumerator E enumerates the language MIN TM and we will reach a contradiction. We will construct the following Turing machine C .

C =“对于以下输入词:

C = "For input word in :

  1. 通过递归定理,得到你自己的<C>描述
  2. By the recursion theorem, obtain your own description of C .
  3. 运行枚举器E ,直到出现机器D,其描述长于描述C。
  4. Run enumerator E until a machine D appears with a description longer than that of C .
  5. 对“中的输入词”模拟动作D。
  6. Simulate the operation of D for input word w ".

由于MIN TM语言是无限的,因此E生成的列表必须包含描述比 C 更长的机器因此,机器C的步骤2在找到图灵机D中某个描述比机器C长的机器后最终会终止。然后C模拟D,因此与它等价。由于C比D短且等价,因此D不可能是最小机器。然而,D出现在E枚举的列表中,这就产生了矛盾。

Since the language MIN TM is infinite, the list generated by E must contain a machine with a longer description than C . Thus, step 2 of machine C eventually terminates after finding some Turing machine D whose description is longer than C . Then C simulates D , and is therefore equivalent to it. Since C is shorter than D and is equivalent to it, D cannot be a minimal machine. However, D appears on the list computed by E , which gives a contradiction.

我们将在这里展示的递归定理的最终应用是不动点定理的变体。函数的不动点是当函数应用于它时不会改变的值。在这种情况下,我们考虑的函数是图灵机描述的可计算变换。我们将证明,对于每个这样的变换,都有一个特定的图灵机,其行为在该变换后不会改变。我们将此定理称为定点递归定理的变体。

The last application of the recursion theorem that we will show here is a variant of the fixed-point theorem. The fixed point of a function is a value that does not change under the application of the function. In this case, we consider functions that are computable transformations of Turing machine descriptions. We will show that for each such transformation, there exists a Turing machine whose behavior does not change under the transformation. We call this theorem the fixed-point variant of the recursion theorem.

定理6.8

Theorem 6.8

t : Σ * Σ * 为可计算函数。那么存在一个图灵机F 其中t ( <F> )描述了一个与F等价的图灵机。我们可以在这里做出假设,如果一个单词不是有效的图灵机编码,那么它描述的是一个立即拒绝任何输入的图灵机。

Let t : Σ * Σ * be a computable function. Then there exists a Turing machine F for which t ( F ) describes a Turing machine equivalent to F . Here we may assume that if a word is not a valid Turing machine encoding, then it describes a Turing machine that immediately rejects any input.

在这个定理中,t起到变换的作用,F是不动点。

In this theorem, t plays the role of a transformation and F is a fixed point.

证明 F为以下图灵机。

Proof Let F be the following Turing machine.

F =“对于输入单词:

F = "For input word in:

  1. 通过递归定理,得到你自己的<F>描述
  2. By the recursion theorem, obtain your own description of F .
  3. 计算t ( <F> )即可获得图灵G的描述。
  4. Compute t ( F ) to obtain a description of the Turing machine G .
  5. 模拟G for w "。
  6. Simulate G for w ".

很明显,< F >t ( < F > ) 描述了等效的图灵机,因为F模拟了G。

It is clear that F and t ( F ) describe equivalent Turing machines, since F simulates G .

6.2

逻辑理论的可判定性

6.2

Decidability of logical theories

数理逻辑是数学的一个分支,研究数学本身。它涉及以下问题:什么是定理?什么是证据?什么是真理?算法可以决定哪些句子是正确的吗?每一个真实的陈述都能被证明吗?在这个关于这个丰富而迷人的世界的简短介绍中,我们将仅介绍其中的几个主题。

Mathematical logic is the branch of mathematics that studies mathematics itself. It deals with questions such as: What is a theorem? What is proof? What is truth? Can an algorithm decide which statements are true? Can every true statement be proven? In this brief introduction to this rich and fascinating world, we will explore just a few of these questions.

我们将重点关注确定数学陈述是真是假的问题,并检查该问题的可判定性。答案取决于这些陈述来自的数学领域。我们将分析两个这样的领域:一个领域我们可以提供一种确定真相的算法,另一个领域的问题是无法判定的。

We will focus on the problem of determining whether mathematical statements are true or false, and investigate the decidability of this problem. The answer depends on the field of mathematics from which the statements come. We will analyze two such fields: one for which we can provide an algorithm to decide whether they are true, and another for which the problem is undecidable.

首先,我们需要定义一种精确的语言来表达我们的问题。我们的目标是能够考虑数学句子,例如

First, we need to define a precise language for formulating our problems. Our goal is to be able to consider mathematical statements such as

  1. q p x , y [ p  >   ( xy  > 1   xy   p )],
  2. q p x , y [ p  >   ( xy  > 1   xy   p )],
  3. a , b , c , n [( abc  > 0 n  > 2)  a n  + b n c n ],并且   
  4. a , b , c , n [( abc  > 0 n  > 2)  a n  + b n c n ], and   
  5. q p x , y [ p  >   ( xy  > 1   ( xy   p   xy   p  + 2))]。
  6. q p x , y [ p  >   ( xy  > 1   ( xy   p   xy   p  + 2))].

第 1 句指出素数有无限多个,其真理自欧几里得时代(大约 2,300 年前)就已为人所知。命题 2 是费马最后定理,直到 1994 年才由 Andrew Wiles 证明。最后,命题 3 指出存在无限多对孪生素数1。这个被称为孪生素数猜想的问题仍然悬而未决。

Sentence 1 states that there are infinitely many primes, and its truth has been known since Euclid, some 2300 years ago. Sentence 2 is Fermat's last theorem, proven only by Andrew Wiles in 1994. Finally, sentence 3 states that there are infinitely many pairs of twin primes 1 . This problem, known as the twin primes conjecture , remains unsolved.

为了考虑我们是否可以自动确定这些句子中哪些句子为真,我们将把这些类型的句子简单地视为单词,并定义由此类句子组成的语言。然后我们可以问以这种方式定义的语言是否是可判定的。

For the purposes of considering whether we could automate the process of determining which of these sentences is true, we will treat such sentences simply as words and define a language consisting of such sentences that are true. We can then ask whether the language so defined is decidable.

为了使我们的考虑更加精确,我们将首先描述该语言的字母表形式:

To make our considerations a bit more precise, we will first describe the alphabet of this language:

{ , , Ø , (, ), , , x , R 1 , …, R k }。

{ , , ¬ , (, ), , , x , R 1 , …, R k }.

符号Ø称为逻辑布尔)运算; “(”和“)”是正则括号;符号称为量词;符号x用于指定变量2,符号R 1 ,..., R k称为关系。

The symbols , , and ¬ are called logical ( Boolean ) operations; "(" and ")" are ordinary brackets; the symbols and are called quantifiers; the symbol x is used to denote variables 2 , and the symbols R 1 , …, R k are called relations.

该公式是在此字母表上正确构造的序列。为了完整起见,我们将在这里概述一个正确构造的公式的技术性定义,尽管是显而易见的,但读者可以跳过这部分并转到下一段。 R i ( x 1 , …, x j )形式的序列是原子(或简单)公式。 j的值是关系符号R i的可论证性正确构造的公式中所有出现的相同关系符号必须具有相同的参数。如果满足这个要求,则单词φ是一个 if 公式

A formula is a well-formed sequence over this alphabet. For the sake of completeness, we will sketch here a technical, though obvious, definition of a well-formed formula, but the reader may skip this part and proceed to the next paragraph. A sequence of the form R i ( x 1 , …, x j ) is an atomic (or simple) formula. The value j is the argument of the relation symbol R i . All occurrences of the same relation symbol in a well- formed formula must have the same argument. Provided that this requirement is met, the word φ is a formula if

  1. 是原子分子式,
  2. is an atomic formula,
  3. 具有形式φ 1 φ 2φ 1 φ 2Øj 1,其中φ 1φ 2是较小的公式,或
  4. has the form φ 1 φ 2 or φ 1 φ 2 or ¬j 1 , where φ 1 and φ 2 are smaller formulas, or
  5. 其形式为x i [ φ 1 ] 或x i [ φ 1 ],其中φ 1是更小的公式。
  6. has the form x i [ φ 1 ] or x i [ φ 1 ], where φ 1 is the smaller formula.

量词可以出现在数学表达式中的任何位置。它的范围是量词变量后面的括号或方括号中包含的句子部分。我们假设所有公式都是正常的 prenex 形式,其中所有量词都放在公式的开头。不受量词约束的变量称为自由变量。不包含自由变量的公式称为句子陈述

A quantifier can appear anywhere in a mathematical expression. Its scope is the sentence fragment enclosed in parentheses or square brackets following the quantifier variable. We assume that all formulas are in prefix normal form , in which all quantifiers are placed at the beginning of the formula. A variable that is not bound by a quantifier is called a free variable. A formula that does not contain any free variables is called a sentence or statement .

6.9

Example 6.9

下面的公式示例中,只有最后一个是句子。

Of the following formula examples, only the last one is a sentence.

  1. R 1 ( x 1 ) R 2 ( x 1 , x 2 , x 3 )
  2. R 1 ( x 1 ) R 2 ( x 1 , x 2 , x 3 )
  3. x 1 [ R 1 ( x 1 ) R 2 ( x 1 , x 2 , x 3 )]
  4. x 1 [ R 1 ( x 1 ) R 2 ( x 1 , x 2 , x 3 )]
  5. x 1 x 2 x 3 [ R 1 ( x 1 ) R 2 ( x 1 , x 2 , x 3 )]
  6. x 1 x 2 x 3 [ R 1 ( x 1 ) R 2 ( x 1 , x 2 , x 3 )]

一旦我们确定了公式的语法,我们将讨论它们的含义。布尔运算和量词有其通常的含义。然而,为了确定关系变量和符号的含义,我们需要定义两个元素。一是变量假定的值所属的宇宙。二是赋予符号特定的关系。正如我们在第 0.2 节(第 9 页)中所解释的,关系是从宇宙中的k元组集合到集合 {TRUE, FALSE} 的函数。关系符号的可论证性必须与指定关系的可论证性相匹配。

After establishing the syntax of formulas, we will discuss their meanings. Boolean operations and quantifiers have their usual meanings. However, in order to establish the meanings of variables and relation symbols, we need to specify two elements. One is the universe to which the values ​​taken by the variables belong. The other is the assignment of certain relations to the symbols. As we explained in Section 0.2 (page 9), a relation is a function from a set of k -tuples over the universe to the set {TRUE, FALSE}. The argument of the relation symbol must match the argument of the assigned relation.

宇宙以及符号关系的分配被称为模型3。形式上,我们会说模型M是一个元组 ( U , P 1 , …, P k ),其中U是宇宙,P 1P k是分配给符号R 1R k的关系。我们有时将模型语言称为一组公式,这些公式仅使用该模型中分配的关系符号,并且使用每个关系符号及其适当的论证。如果φ是模型语言中的句子,则φ在该模型中要么为真,要么为假。如果φ在模型M中为真,我们就说M是φ的模型。

The universe together with the assignment of relations to symbols is called a model 3 . Formally, we will say that a model M is a tuple ( U , P 1 , …, P k ), where U is the universe and P 1 to P k are relations assigned to symbols R 1 to R k . We will sometimes refer to the model language as a set of formulas that use only the relation symbols assigned in the model and that use each relation symbol with the proper argument. If φ is a sentence in the model language, then φ is either true or false in the model. If φ is true in the model M , then we say that M is a model for φ .

新定义的积累可能会让人不知所措,但让我们重点关注我们制定这些定义的目的。我们想要定义一种精确的数学表达式语言,通过它,我们将能够提出这样的问题:是否可以通过算法来决定哪些是正确的,哪些是错误的。接下来的两个示例应该对此有所帮助。

This accumulation of new definitions can be overwhelming, but let us focus on the purpose for which we have formulated them. We want to define a precise language for mathematical expressions, so that we can formulate the question of whether it is possible to decide algorithmically which of them are true and which are false. The next two examples should help with this.

6.10

Example 6.10

Φ为命题x x [ R 1 ( x , y ) R 1 ( y , x )]。设M 1 = ( N , ≤) 是一个模型,其宇宙是自然数集,并且为符号R 1指定“小于或等于”关系。显然,在M 1模型中, φ成立,因为对于任意两个自然数a和 b , abba成立。然而,如果模型M 1为符号R 1分配关系“小于”而不是“小于或等于”,则Φ将不为真,因为在xy相等的情况下不满足。

Let Φ be the proposition x x [ R 1 ( x , y ) R 1 ( y , x )]. Let M 1 = ( N , ≤) be a model whose universe is the set of natural numbers and which assigns the relation "less than or equal than" to the symbol R 1 . It is obvious that φ is true in M ​​1 , since for any two natural numbers a and  b it is true that ab or ba . However, if the model M 1 assigned the relation "less than" to the symbol R 1 instead of "less than or equal than", then Φ would not be true, since it is not satisfied for x and y to be equal.

如果我们事先知道什么关系将分配给R i,我们可以使用该关系的惯用符号而不是R i,大概是中缀表示法,而不是如果这是该符号的标准用法。因此,给定M 1模型,我们可以将Φ写为x x [ xy yx ]。

If we know in advance what relation will be assigned to R i , we can use the customary symbol for that relation instead of R i , presumably in infix notation, rather than if this is the standard usage of the symbol. Thus, given the model M 1 , we could write Φ as x x [ xy yx ].

6.11

Example 6.11

M 2是一个模型,其宇宙是实数集R ,并且将关系PLUS分配给符号R 1,如果a + b = c ,则某处PLUS ( a , b , c )=TRUE 。那么M 2是φ = y x [ R 1 ( x , x , y )]的模型。但是,如果我们使用集合N而不是R作为M 2模型中的宇宙,则该陈述将是错误的。

Let M 2 be a model whose universe is the set of real numbers R and which assigns to the symbol R 1 the relation PLUS , somewhere PLUS ( a , b , c ) = TRUE if a + b = c . Then M 2 is a model for φ = y x [ R 1 ( x , x , y )]. However, if in the model M 2 we used the set N instead of R as the universe , this statement would be false.

如例 6.10 所示,我们可以写φ = y x [ x + x = y ] 而不是 [ R 1 ( x , x , y )],只要我们事先知道我们将赋值1R与符号

As in Example 6.10, we can write φ = y x [ x + x = y ] instead of [ R 1 ( x , x , y )], if we know in advance that we will assign an addition relation to the symbol R 1 .

我们需要一个最终定义作为下一节的准备。如果M是一个模型,那么该模型语言中所有真实句子的集合将称为M的模型论,我们将其写为 Th( M )。

We need one final definition in preparation for the next section. If M is a model, then the set of all true sentences in the language of that model will be called the model theory of M , which we write Th( M ).

可判定理论

Decidable theory

数论是数学最古老的分支之一,也是最困难的分支之一。几个世纪以来,许多关于自然数加法和乘法运算的看似无辜的定理一直吸引着数学家的注意力,前面提到的孪生素数假设就是例证。

Number theory is one of the oldest branches of mathematics and at the same time one of the most difficult. Many seemingly innocent theorems about natural numbers with operations of addition and multiplication have occupied the attention of mathematicians for centuries, an example of which is the aforementioned conjecture of twin primes.

数理逻辑最伟大的成就之一是阿隆佐·丘奇(Alonzo Church)的成果,他在库尔特·哥德尔(Kurt Gödel)的工作的基础上证明了在一般情况下没有算法可以决定数论的陈述是真是假。形式上,( N , +, ×) 是指一个模型,其宇宙是自然数4,具有通常的关系 + 和 ×。 Church 表明,该模型的理论Th( N , +, ×) 是不可判定的。

One of the greatest achievements of mathematical logic is the result obtained by Alonzo Church, who, building on the work of Kurt Gödel, proved that in the general case no algorithm can decide whether the statements of number theory are true or false. Formally, by ( N , +, ×) we mean a model whose universe is the natural numbers 4 with the usual relations + and ×. Church showed that Th( N , +, ×), the theory of this model, is undecidable.

在我们研究这个不可判定的理论之前,让我们首先尝试分析一个可判定的理论。令 ( N , +) 为同一模型,但没有 × 关系。他的理论是Th( N ,+)。例如,公式x y [ x + x = y ] 为真,因此属于 Th( N , +),但公式y y [ x + x = y ] 为假,因此不属于 Th ( N , +)到Th( ,+)N

Before we look at this undecidable theory, let us first try to analyze one that is decidable. Let ( N , +) be the same model, but without the relation ×. Its theory is Th( N , +). For example, the formula x y [ x + x = y ] is true and thus belongs to Th( N , +), but the formula y x [ x + x = y ] is false and thus does not belong to this theory.

定理6.12

Theorem 6.12

Th( N , +) 是可判定的。

Th( N , +) is decidable.

证明的概念 这个证明是我们在第 1 章中介绍的有限自动机理论的一个有趣且重要的应用。我们将使用的有限自动机的属性出现在问题 1.32(第 88 页)中,其中向读者询问表明只要输入数据以适当的形式呈现,这些自动机就能够执行加法。该输入并行描述三个数字,将每个数字的一​​位表示为八元素字母表的单个符号。现在,我们将使用此方法的推广来并行表示i元组,使用包含 2 i 个符号的字母表。

The Concept of the Proof This proof is an interesting and nontrivial application of the theory of finite automata that we introduced in Chapter 1. The property of finite automata that we will use appeared in Problem 1.32 (page 88), in which the reader was asked to show that these automata can perform addition, provided that the input is given in an appropriate form. This input describes three numbers in parallel, representing one bit of each number as a single symbol of an eight-element alphabet. We now generalize this method to represent i -tuples in parallel, using an alphabet of 2 i symbols.

我们将提出一种算法,可以确定其输入数据,即属于模型语言(N ,+)的句子Φ在该模型中是否为真。让

We will present an algorithm that can determine whether its input, a sentence Φ belonging to the model language ( N , +), is true in this model. Let

Φ = Q 1 x 1 Q 2 x 2 …Q l x l [ Φ ],

Φ = Q 1 x 1 Q 2 x 2 …Q l x l [ φ ],

其中每个 Q 1 , …,Q l表示,并且φ是使用变量 x 1 , …, x l的无量词公式。对于从 0 到l的每个i,我们将公式Φ i定义为

where each Q 1 , …,Q l represents either or , and φ is a quantifier-free formula that uses variables x 1 , …, x l . For each i from 0 to l we define the formula Φ i as

Φ i = Q i +1 x i +1 Q i +2 x i +2 … Q l x l [ φ ]。

Φ i = Q i +1 x i +1 Q i +2 x i +2 … Q l x l [ φ ].

所以Φ 0 = ΦΦ l = Φ

So Φ 0 = Φ and Φ l = φ .

公式Φi 个自由变量。对于a 1 , …, a i N令符号Φ i ( a 1 , …, a i ) 表示通过替换Φ中的常量a 1 , …, a变量x 1 , …, x i形成的句子

The formula Φ i has i free variables. For a 1 , …, a i N , let the notation Φ i ( a 1 , …, a i ) denote the sentence formed by replacing the variables x 1 , …, x i in Φ i with the constants a 1 , …, a i .

对于从 0 到l 的每个i ,该算法构造一个有限自动机A i,它识别一组代表i组数字的单词,这些数字使Φ i为真。该算法首先使用问题 1.32 解决方案中提出的方法的推广直接构造A l 。然后对于每个i,从l开始递减到 1,它使用A i构造A i −1。最后,在构建 A 0后,自动机检查A 0是否接受空字。如果是,则 Φ为真且算法接受。

For each i from 0 to l, the algorithm constructs a finite automaton A i that recognizes a set of words representing i -tuples of numbers that make Φ i true. The algorithm begins by directly constructing A l , using a generalization of the method presented in the solution to Problem 1.32. Then, for each i , starting from l and going down to 1, it uses A i to construct A i −1 . Finally, after constructing  A 0 , the automaton checks whether A 0 accepts an empty word. If so, Φ is true and the algorithm accepts.

证明 对于i > 0,我们定义一个字母表

Proof For i > 0 we define an alphabet

如您所见,Σ i包含所有由 0 和 1 组成的大小为i的列。字母表Σ i上方的每个单词代表i 个二进制整数(按行读取)。我们还定义Σ 0 = {[ ]},其中 [ ] 是一个符号。

As you can see, Σ i contains all columns of size i consisting of zeros and ones. Each word over the alphabet Σ i represents i binary integers (read row by row). We also define Σ 0 = {[ ]}, where [ ] is a symbol.

我们现在提出分辨率算法Th( N ,+)。对于输入单词Φ,其中Φ是一个句子,算法的工作原理如下。它写入Φ并为从 0 到l的每个i定义Φ i,如证明概念中所示。对于每个这样的i,基于公式Φ i,它构造一个有限自动机A i,它接受Σ i上对应于i元组a 1 , …, a i 的单词,使得Φ i ( a 1 , …, a i )是真的。

We now present an algorithm for resolving Th( N ,+). For an input word Φ , where Φ is a proposition, the algorithm works as follows. It writes Φ and defines Φ i for each i from 0 to l , as in the proof concept. For each such i , from the formula Φ i constructs a finite automaton A i that accepts words over Σ i corresponding to i -tuples a 1 , …, a i such that Φ i ( a 1 , …, a i ) is true.

为了构造第一台机器A l,我们注意到Φ l = φ是原子公式的布尔组合。 Th( N ,+)中的原子式是单次加法。人们可以构建有限自动机,该自动机将计算与单次加法相对应的每个单独关系,然后将它们组合起来以获得自动机A l。这利用了正则语言由于并集、交集和补集操作而产生的闭包来计算原子公式的布尔组合。

To construct the first machine A l , we note that Φ l = φ is a Boolean composition of atomic formulas. An atomic formula in the language Th( N ,+) is a single addition. One can construct finite-state automata that compute each of the individual relations corresponding to the single additions, and then combine them to obtain the automaton A l . This exploits the closure of regular languages ​​under the operations of union, intersection, and complement to compute the Boolean composition of atomic formulas.

然后我们将展示如何从自动机A i +1构造A i。如果Φ i = x i +1 Φ i +1,那么我们构造A i使其行为类似于A i +1 ,只不过它不确定地猜测a i +1的值,而不是将其作为输入的一部分接收。

Next, we show how to construct A i from the automaton A i +1 . If Φ i = x i +1 Φ i +1 , then we construct A i to function just like A i +1 except that it nondeterministically guesses the value of a i +1 , rather than receiving it as part of the input.

更具体地说,A i包含机器A i +1的每个状态的状态和新的初始状态。每次A读取一个符号

More precisely, A i contains the state for each state of the automaton A i +1 and the new initial state. Each time A i reads a symbol

其中每个b j ∈ {0, 1} 是数字a j 的一位,非确定性地猜测z {0,1} 并模拟输入符号A+1的动作

where each b j {0, 1} is a bit of a j , nondeterministically guesses z {0,1} and simulates the action A i + 1 for the input symbol

最初,A i不确定地猜测a+1的初始位对应于数字a 1, ..., a中跳过的前导零,使用从新初始状态到A 的所有状态的 ε 转换来非确定性分支执行。对于由符号组成的输入字, i +1可以从其初始状态到达

Initially, A i nondeterministically guesses the starting bits of a i + 1 corresponding to the skipped leading zeros in the numbers a 1 , …, a i , nondeterministically branching the execution using ε-transitions from the new initial state to all states that A i + 1 could reach from its initial state for input words composed of symbols

包含在Φ+1中。显然,如果存在a i +1A i +1接受 ( a 1 , …, a i , a i +1 ),则A i接受其输入 ( a 1 , …, a i )

contained in Φ i +1 . It is clear that A i accepts its input ( a 1 , …, a i ) if there exists such a a i +1 that A i +1 accepts ( a 1 , …, a i , a i +1 ).

如果Φ i = x i +1 Φ i +1,那么这相当于Ø∃ x i +1 Ø Φ i +1。因此,我们可以使用先前的量词∃构造来构造一个识别A i +1的补码的有限自动机,然后应用补码来获得A i

If Φ i = x i +1 Φ i +1 , then this is equivalent to ¬∃ x i +1 ¬ Φ i +1 . We can therefore construct a finite-state automaton recognizing the complement of A i +1 by using the previous construction for the quantifier , and then apply the complement to obtain A i .

当且仅当Φ 0为真时,有限自动机A 0接受任何输入。因此,在最后一步中,算法检查A 0是否接受ε。如果是,则Φ为真,算法接受;否则它会拒绝。

A finite state machine A 0 accepts any input if and only if Φ 0 is true. Thus, in the final step, the algorithm checks whether A 0 accepts ε. If so, Φ is true and the algorithm accepts; otherwise, it rejects.

不可判定理论

Undecidable theory

正如我们之前提到的,Th( N ,+,×)是一个不可判定的理论。没有算法可以决定数学陈述的真假,即使我们将它们仅限于语言(N,+,×)。这个定理具有重大的哲学意义,因为它表明数学不能自动化。我们将陈述这个定理,但只给出其证明的简要概述。

As we mentioned earlier, Th( N ,+,×) is an undecidable theory. There is no algorithm that can decide the truth or falsity of mathematical statements, even when we restrict them to the language ( N ,+,×). This theorem has great philosophical significance, because it shows that mathematics cannot be automated. We will state this theorem, but give only a brief sketch of its proof.

定理6.13

Theorem 6.13

语言 Th( N ,+,×) 是不可判定的。

The language Th( N ,+,×) is undecidable.

这个定理的证明在概念上并不困难,尽管涉及很多细节。它遵循与第 4 章中其他不可判定性证明相同的方案。我们将使用前面描述的计算历史方法(第 220 页),通过将A TM语言简化为 Th( N ,+,×) 语言来证明 Th( N ,+,×) 语言是不可判定的。这种减少的存在是基于以下引理。

The proof of this theorem is not conceptually difficult, although it involves a great deal of detail. It follows the same scheme as the other undecidability proofs of Chapter 4. We show that the language Th( N ,+,×) is undecidable by reducing the language A TM to it , using the computation history method described earlier (page 220). The existence of this reduction relies on the following lemma.

引理 6.14

Lemma 6.14

M为图灵机,w为单词。根据机器M和单词w的描述,我们可以用语言 ( N ,+,×)构造一个公式Φ M, w,其中包含单个自由变量x,使得语句x Φ M, w为真,如果并且仅当M接受In时。

Let M be a Turing machine and w be a word. From the description of the machine M and the word w we can construct a formula Φ M, w in the language ( N ,+,×) that contains a single free variable x such that the sentence x Φ M, w is true if and only if M accepts w .

证明的概念 公式Φ M, w “表示” x是(经过适当编码后) w的可接受计算历史M。当然, x实际上只是一个相当大的整数,但它以可以使用 + 和 × 运算检查的形式表示计算历史。

Concept of Proof The formula Φ M, w "says" that x is (when appropriately encoded) an accepting computation history of M for w . Of course, x is in reality just a fairly large integer, but it represents a computation history in a form that can be checked using the + and × operations.

Φ M, w的实际构造过于复杂,无法在此介绍。使用 + 和 × 运算,对计算历史中出现的各个符号进行解码,并检查机器Mw的初始配置是否正确,然后每个配置是否从前一个配置正确得出,最后检查最后一个配置是否是接受。

The actual construction of Φ M, w is too complex to be shown here. It uses the + and × operations to decode the single symbols occurring in the computation history and checks whether the initial configuration of M for w is correct, then whether each configuration correctly follows from the preceding one, and finally whether the last configuration is accepting.

定理 6.13 的证明我们将通过从A TM映射到 Th( N , +, ×) 呈现约简使用引理 6.14,归约根据输入词M , w 构造公式Φ M, w 。然后它返回句子x Φ M, w

Proof of Theorem 6.13 We present the reduction by mapping from A TM to Th( N , +, × ). The reduction constructs a formula Φ M, w from an input wordM , w , using Lemma 6.14. Then it returns the sentencex Φ M, w .

接下来,我们将概述库尔特·哥德尔提出的著名不完备性定理的证明。非正式地说,该定理指出,在任何将数论中可证明性概念形式化的一致系统中,都存在一些无法被证明的真命题。直观地,句子Φ的形式证明 p是句子序列S 1 , S 2 , …, S l,其中S l = Φ。每个S i都遵循前面的句子和数论的某些基本公理,使用简单而明确的推理规则。我们这里没有篇幅来介绍证明的概念;就我们的目的而言,假设证据的两个合理属性就足够了。

Next, we will sketch a proof of Kurt Gödel's famous incompleteness theorem . Informally, the theorem states that in any consistent system formalizing the notion of provability in number theory, there are some true statements that cannot be proven. Intuitively, a formal proof p of a statement Φ is a sequence of statements S 1 , S 2 , …, S l , where S l = Φ . Each S i follows from the preceding statements and from certain basic axioms of number theory, using simple and unambiguous rules of inference. We do not have the space here to present the concept of proof; for our purposes, it will suffice to assume two reasonable properties of proofs.

  1. 公式证明的正确性可以通过机器来检查。形式上,我们要求语言 { 〈Φ , p〉 : p是Φ的证明} 是可判定的。
  2. The correctness of a proof of a formula can be checked by a machine. Formally, we require that the language { 〈Φ , p〉 : p is a proof of Φ } be decidable.
  3. 命令系统正确。这意味着如果一个陈述是可证明的(即有证据),那么它就是真的。
  4. The proof system is sound. This means that if a statement is provable (i.e. has a proof), then it is true.

如果指挥系统满足这两个条件,则以下三个命题成立。

If the proof system satisfies these two conditions, then the following three theorems are true.

定理6.15

Theorem 6.15

Th( N ,+,×)中的可证明句子集合在图灵意义上是可识别的。

The set of provable sentences in Th( N ,+,×) is Turing-recognizable.

证明如果Φ可证明, 以下算法P接受其输入Φ 。算法P使用证明检查机检查每个单词作为句子Φ的候选证明p,该证明检查机的存在遵循证明系统的第一个属性。如果它确定这些候选者中的任何一个是证据,它就会接受。

Proof The following algorithm P accepts its input Φ , if Φ is provable. Algorithm P tests each word as a candidate for a proof p of the sentence Φ , using a proof checking machine whose existence follows from the first property of proof systems. If it determines that any of these candidates is a proof, it accepts.

我们现在可以使用前面的定理来证明我们版本的不完备性定理。

We can now use the previous theorem to prove our version of the incompleteness theorem.

定理6.16

Theorem 6.16

一些属于 Th( N ,+,×) 的真命题是不可证明的。

Some true sentences belonging to Th( N ,+,×) are not provable.

证明 我们将通过还原矛盾来提出证明。我们假设所有真实的陈述都可以被证明。使用这个假设,我们将描述一个算法D,用于通过否定定理 6.13 来判定句子是否为真。

Proof We will present a proof by reduction to contradiction. We assume that all true statements can be proven. Using this assumption, we describe an algorithm D that decides whether statements are true, contradicting Theorem 6.13.

对于输入词Φ,D算法的工作原理是针对输入ΦØf并行运行由定理 6.15 证明得出的P算法。其中一个句子是正确的,因此根据我们的假设,它是可证明的。因此,P必须针对这两个输入之一停止。根据证明系统的第二个性质,如果Φ可证明,则意味着Φ为真;如果Øf可证明,则Φ为假。因此,算法D可以解析Φ 的真假。

For input Φ, algorithm D works by running the algorithm P that follows from the proof of Theorem 6.15 in parallel for inputs Φ and ¬f . One of these statements is true, so by our assumption it is provable. Therefore, P must halt for one of these two inputs. By the second property of provable systems, if Φ is provable, then Φ is true; and if ¬f is provable, then Φ is false. Thus, algorithm D can decide whether Φ is true or false .

在本节的最后一个定理中,我们使用递归定理来显式地显示属于语言 ( N ,+,×) 的句子是正确的但不可证明。在定理 6.16 中,我们证明了这样一个句子的存在性,但我们没有展示它是什么样的,我们现在要做。

In the last theorem of this section we use the recursion theorem to explicitly show a sentence belonging to the language ( N ,+,×) that is true but not provable. In Theorem 6.16 we proved the existence of such a sentence, but we did not show what it looks like, which we do now.

定理6.17

Theorem 6.17

该定理证明中描述的句子φ unprovable是不可证明的。

The sentence φ unprovable , described in the proof of this theorem, is unprovable.

证明的概念 我们将利用递归定理构造一个句子,表示“这句话不可证明”,以实现自引用。

The Concept of Proof We construct a sentence that states "This sentence is not provable" by using the recursion theorem to obtain self-reference.

证明 S为图灵机,运行如下。

Proof Let S be a Turing machine that operates as follows.

S =“对于任何输入:

S = "For any input:

  1. 使用递归定理获得您自己的S 〉描述。
  2. Obtain your own description of S using the recursion theorem.
  3. 使用引理 6.14构造语句φ = Ø c [ Φ S, 0 ]。
  4. Construct the sentence φ = ¬ c [ Φ S, 0 ] using Lemma 6.14.
  5. 针对输入词φ运行来自定理6.15证明的算法P。
  6. Run algorithm P from the proof of Theorem 6.15 for input word φ .
  7. 如果步骤 3 接受,则接受。”
  8. If step 3 is acceptable, then accept .”

φ不可证明为算法S的步骤 2 中描述的句子φ 。当且仅当S不接受0(单词0是任意选择的)时,该语句才成立。

Let φ unprovable be a sentence φ described in step 2 of algorithm S . This sentence is true if and only if S does not accept 0 (word 0 was chosen arbitrarily).

如果P发现证据φ无法证明S接受0,因此该陈述必定是错误的。虚假陈述无法被证明,因此这种情况不可能发生。唯一剩下的可能性是P未能找到φ不可证明证明,因此S不接受0。但根据论文,无法证明φ为真。

If P finds a proof of φ unprovable , S accepts 0 , and so the sentence must be false. A false sentence cannot be provable, so this situation cannot occur. The only remaining possibility is that P fails to find a proof of φ unprovable , and so S does not accept 0 . But then φ unprovable is true, according to the thesis.

6.3

图灵可约性

6.3

Turing reducibility

我们在第五章中介绍了可归约性的概念,作为一种使用一个问题的解决方案来解决其他问题的方法。如果A可简化为B并且我们找到了问题B的解,那么我们就可以获得问题A的解。然后我们描述了通过映射进行约简,这是约简性的一种特殊形式。但是,通过映射进行归约是否以最一般的方式捕捉了我们关于可归约性的直观概念?答案是不。

We introduced the concept of reducibility in Chapter 5 as a way of using the solution to one problem to solve other problems. If A is reducible to B and we find a solution to B , then we can obtain a solution to A . Next, we described reduction by mapping, which is a special form of reducibility. But does reduction by mapping capture our intuitive concept of reducibility in the most general way? The answer is no.

例如,考虑两种语言A TMA TM。直观上,它们可以相互简化,因为一个解决方案可以通过简单地反转答案来解决另一个问题。然而,我们知道A TM 不能通过映射到A TM来简化,因为A TM是图灵可识别的,而A TM不是。我们现在介绍一种更通用的可归约形式,称为图灵可归约,它更好地捕捉了可归约的直观概念。

For example, consider two languages ​​A TM and A TM . Intuitively, they are reducible to each other, since the solution to one can be used to solve the other by simply inverting the answer. However, we know that A TM is not reducible by mapping to A TM , since A TM is Turing recognizable and A TM is not. We now introduce a more general form of reducibility, called Turing reducibility, which better captures the intuitive concept of reducibility.

定义 6.18

Definition 6.18

语言B的预言机是一个外部设备,能够确定中的任何单词是否属于B。具有预言机图灵机是经过修改的图灵机,具有向预言机提问的附加功能。一个带有预言机的图灵机,其中包含语言B的预言机M B

An oracle for language B is an external device that is able to determine whether any word in belongs to B . A Turing machine with an oracle is a modified Turing machine with the additional ability to ask questions to the oracle. A Turing machine with an oracle containing an oracle for language B will be written as M B .

我们在这里不关心神谕如何确定其答案。我们使用预言机一词来强调这种神奇的能力,并且我们将把预言机视为无法通过普通算法判定的语言,如下例所示。

We are not concerned here with how the oracle determines its answers. We use the term oracle to emphasize this magical ability, and we will consider oracles for languages ​​that are not decidable by ordinary algorithms, as the following example shows.

6.19

Example 6.19

考虑语言A TM的预言机。带有 ATM 预言机的图灵机可以比普通图灵机解析更多的语言。这样的机器(显然)可以通过查询预言机的输入来解析ATM语言本身。

Consider an oracle for the language A TM . A Turing machine with an oracle A TM can arbitrate more languages ​​than an ordinary Turing machine. Such a machine can (obviously) arbitrate the language A TM itself by querying the oracle for input.

它还可以使用以下称为T ATM 的过程来解决E TM(图灵机的语言空性测试问题)。

It can also solve E TM , the problem of testing the emptiness of a language for Turing machines, using the following procedure called T ATM .

T ATM = "对于输入词M ,其中M是图灵机:

T ATM = "For input word M , where M is a Turing machine:

  1. 构建以下机器N。

    N = 对于任何输入:

    1. 对属于Σ *的所有字并行运行M。
    2. 如果M接受这些词中的任何一个,则接受
  2. Construct the following machine N .

    N = For any input:

    1. Run M in parallel for all words belonging to Σ *.
    2. If M accepts any of these words, accept .
  3. 要求预言机判断是否N , 0 A TM
  4. Ask the oracle to determine whether N , 0 A TM .
  5. 如果预言机回答“否”,则接受;如果是,则拒绝
  6. If the oracle answers NO, accept ; if YES, reject ."

如果机器语言M不为空,则N接受任何输入,特别是输入0。因此,预言机将回答“是”,并且T ATM将拒绝输入。相反,如果机器语言M为空,则TATM接受输入。因此,T ATM解析了语言E TM。我们说E TM相对于 A TM是可判定的。这给我们带来了图灵意义上的可归约性的定义。

If the language of the machine M is not empty, then N accepts any input, and in particular the input 0 . Thus, the oracle will answer YES, and T ATM will reject the input . Conversely, if the language of the machine M is empty, then T ATM will accept the input. Thus, T ATM decides the language E TM . We say that E TM is decidable with respect to A TM . This brings us to the definition of Turing reducibility.

定义 6.20

Definition 6.20

语言A图灵可约化为语言B 的,如果它相对于B可判定,我们将其写为A T B

A language A is Turing reducible to a language B , written AT B , if it is decidable with respect to B .

例 6.19 表明 ETM 可图灵还原为 ATM。图灵可约性满足我们直观的可约性概念的要求,如以下定理所示。

Example 6.19 shows that ETM is Turing reducible to ATM. Turing reducibility satisfies the requirements of our intuitive conception of reducibility, as the following theorem shows.

定理6.21

Theorem 6.21

如果AT BB是可判定语言,则A是可判定语言。

If AT B and B is a decidable language, then A is a decidable language.

证明 如果B是可判定语言,那么我们可以用实际的判定过程B来替换语言B的预言用正则图灵机替换使用预言机解析A 的图灵机

Proof If B is a decidable language, then we can replace the oracle for B with an actual procedure that decides B . So we can replace the Turing machine that decides A by means of an oracle with an ordinary Turing machine.

图灵可约性是映射约简的概括。如果Am B,则AT B ,因为我们可以使用映射约简来表示具有相对于B解析A 的预言机的图灵机。

Turing reducibility is a generalization of reduction by mapping. If Am B , then AT B , since we can use reduction by mapping to represent a Turing machine with an oracle that decides A with respect to B .

带有oracle A TM的图灵机非常强大。它可以解决许多使用普通图灵机无法解决的问题。然而,即使如此强大的机器也无法解析所有语言(见练习6.4)。

A Turing machine with an oracle A TM is very powerful. It can solve many problems that are not solvable using ordinary Turing machines. However, even such a powerful machine cannot resolve all languages ​​(see Exercise 6.4).

6.4

信息的概念

6.4

The concept of information

算法信息的概念是计算机科学的基础。然而,虽然丘奇-图灵假说提供了算法的通用定义,但还没有同样令人信服的信息定义。根据需要,使用许多不同的定义,而不是单一的、通用的信息定义。在本节中,我们将介绍一种使用可计算性理论来定义信息的可能方法。

The concepts of algorithm and information are fundamental to computer science. However, while the Church-Turing hypothesis provides a universal definition of an algorithm, no equally convincing definition of information is known. Instead of a single, universal definition of information, many different definitions are used, depending on the needs. In this section, we present one possible way to define information, using computability theory.

让我们从一个例子开始。考虑以下两个二进制数字序列的信息内容:

Let's start with an example. Consider the information content of the following two sequences of binary numbers:

A = 0101010101010101010101010101010101010101

A = 0101010101010101010101010101010101010101

B =1110010110100011101010000111010011010111

B = 1110010110100011101010000111010011010111

直观上,序列A包含很少的信息,因为它只是模式01的二十倍重复。相反,序列B似乎包含更多信息。

Intuitively, sequence A contains little information, since it is merely a twenty-fold repetition of pattern 01 . Conversely, sequence B appears to contain more information.

我们可以使用这个简单的例子来说明我们想要呈现的信息定义背后的想法。我们将对象中包含的信息量定义为该对象的最小可能表示(描述)的大小。通过对象描述,我们指的是对象的精确且明确的特征,允许仅基于描述来重建它。因此,序列A包含很少的信息,因为它几乎没有描述,而序列B显然包含更多信息,因为似乎没有更短的描述。

We can use this simple example to illustrate the idea behind the definition of information we want to present. We will define the amount of information contained in an object as the size of the smallest possible representation (description) of that object. By description of an object we mean a precise and unambiguous characteristic of the object, allowing it to be reconstructed from the description alone. Thus, sequence A contains little information, since it has a small description, while sequence B clearly contains more information, since there does not seem to be a shorter description for it.

当我们想要确定对象中包含的信息量时,为什么我们只考虑最短的描述?我们总是可以通过将对象的副本直接放置在描述中来描述对象,例如单词。因此很明显,我们可以使用包含B副本的 40 位数组来描述前面显示的单词B。这种类型的描述永远不会比对象本身短,并且不会告诉我们它包含的信息量。然而,如果我们有一个明显比对象短的描述,我们可以得出结论,这个对象包含的信息可以被压缩到一个很小的体积中,因此这个信息量不可能很大。所以最短描述的大小决定了信息量。

Why do we consider only the shortest descriptions when we want to determine the amount of information contained in an object? We can always describe an object, such as a word, by including a copy of that object directly in the description. It is therefore obvious that we can describe the word B shown earlier using a 40-bit array containing a copy of B . This type of description is never shorter than the object itself and tells us nothing about the amount of information contained in it. However, if we have a description that is significantly shorter than the object, we can conclude that the information contained in the object can be compressed into a small volume, so the amount of information cannot be very large. Thus, the size of the shortest description determines the amount of information.

现在我们将形式化这个直观的想法。这并不难,但是我们需要做一些前期工作。首先,我们将考虑范围限制为二进制字符串对象。任何其他对象都可以表示为二进制字符串,因此这一警告并不限制我们理论的范围。其次,我们只会考虑本身是二进制序列的描述。通过施加这个要求,我们将能够轻松地将对象的长度与其描述的长度进行比较。在下一节中,我们将考虑允许的描述类型。

We now formalize this intuitive idea. This is not difficult, but we need to perform some preliminary operations. First, we will restrict our considerations to objects that are binary strings. Any other objects can be represented as binary strings, so this restriction does not limit the scope of our theory. Second, we will consider only descriptions that are themselves binary strings. By imposing this requirement, we can easily compare the length of an object with the length of its description. In the next section, we consider the allowed types of descriptions.

最小长度描述

Minimum Length Descriptions

可以使用许多不同的描述语言来定义信息。选择特定语言会影响定义的特征。我们的描述语言将基于算法。

Many different description languages ​​can be used to define information. The choice of a specific language affects the characteristics of the definition. Our description language will be based on algorithms.

使用算法来描述单词的一个明显方法是构造一个图灵机,当在空白磁带上运行时,它会打印单词,然后将机器本身表示为单词。这样,代表图灵机的词就是对原词的描述。这种方法的缺点是图灵机无法通过其转换函数紧凑地表示一串符号。为了表示长度为n位的字,我们可能需要转换函数表中的n 个状态和n行。这会导致描述对于我们的需要而言过长。相反,我们将使用以下更简洁的描述性语言。

The obvious way to use algorithms to describe words is to construct a Turing machine that will print out the word when run with a blank tape, and then represent the machine itself as a word. In this way, the word that represents the Turing machine is a description of the original word. The disadvantage of this approach is that the Turing machine cannot compactly represent a sequence of symbols by its transition function. To represent a word of length n bits, we might need n states and n rows in the transition function table. This would give a description that is excessively long for our purposes. Instead, we will use the following, more compact language for description.

我们将使用图灵机M和作为M输入的二进制序列w来描述二进制序列x 。描述长度是表示Mw的组合长度。我们将使用将多个对象编码为一个二进制字符串M , w 的常用符号来编写此描述。不过,这一次我们必须要注意编码操作< ·,· >,因为我们需要得到最简洁的结果。我们将单词M , w 定义为M w,我们简单地将二进制字符串w连接到二进制编码M的末尾。M机器〈M〉编码可以用任何标准方式完成,除了我们将在下一段中描述的特殊情况(第一次阅读本节时,您无需担心这种微妙的情况。现在,您可以简单地跳过下一段及其后面的图。)

We will describe a binary string x in terms of a Turing machine M and a binary string w as input to M . The length of the description is the combined length of the representation of M and w . We will write this description using our usual notation for encoding multiple objects into a single binary string M , w . This time, however, we need to pay attention to the encoding operation · , · , since we need to get the result as concise as possible. We will define the word M , w as M w , where we simply concatenate the binary string w onto the end of the binary encoding of M . The encoding M of M can be done in any standard way, except for special situations that we will describe in the next section. (When you first read this section, you don't need to worry about this subtle coincidence. For now, you can simply skip the next paragraph and the figure that follows it.)

当将w添加到<M>的末尾以获得x 的描述时,如果我们无法描述本身轻松确定<M>w连接点,我们可能会遇到麻烦否则,可能有很多方法可以将描述<M>w分割语法有效的图灵机和输入数据,因此描述将是不明确的,因此是不正确的我们通过确保能够找到描述M w分裂成M i w的位置来避免这个问题。例如,这可以通过将每个位 <M> 写入两次来完成即将0 写入 00 将 1 写入 11,然后附加 01 来标记分割点。这个想法如下图所示,说明了某个单词x的< M , in >的描述。

In appending w to the end of M to obtain a description of x , we may run into trouble if the junction point of M and w cannot be easily determined from the description itself. Otherwise, it may turn out that there are many ways to split the description M w into a syntactically correct Turing machine and its input, so that the description would be ambiguous and hence invalid. We avoid this problem by ensuring that we can locate where the description M w splits into M and w . One way to do this is to write each bit of M twice , that is, write 0 as 00 and 1 as 11, and then append 01 to mark the split point. This idea is illustrated in the following figure, which illustrates the description M , w of some word x .

6.22

描述某个单词 x 的<M,w>格式示例

Figure 6.22

Example of the description format 〈M,w〉 of a certain word x

现在我们已经确定了描述语言,我们可以定义单词中包含的信息量的度量。

Now that we have fixed the description language, we can define a measure of the amount of information contained in a word.

定义 6.23

Definition 6.23

x为二进制序列。x 的最小描述 写为d ( x ),是最短的单词M , w ,其中输入单词w的图灵机M在将x写入其磁带后停止。如果有很多这样的单词,我们按字典顺序选择第一个。5 x的描述复杂度,写作 K( x ),为

Let x be a binary sequence. The minimal description of x , written as d ( x ), is the shortest word M , w , where a Turing machine M for input word w halts after writing x to its tape. If there are multiple such words, we choose the first one lexicographically. The description complexity of 5 x , written K( x ), is

K ( x ) = | d ( x )|。

K ( x ) = | d ( x )|.

换句话说,K( x ) 是x 的最短描述的长度。K ( x )的定义旨在传达对单词x所包含的信息量的直观理解。我们现在可以提供一些关于描述性复杂性的简单观察。

In other words, K( x ) is the length of the shortest description of x . The definition of K ( x ) is intended to convey an intuitive understanding of the amount of information contained in a word x . We can now make some simple observations about description complexity.

定理6.24

Theorem 6.24

c x [K( x ) ≤ | x | + c ]

c x [K( x ) ≤ | x | + c ]

该定理指出,单词的描述复杂性最多比其长度大一个常数。这个常数是通用的,与任何特定的单词无关。

This theorem states that the descriptive complexity of a word is greater than its length by at most a constant amount. This constant is universal, independent of any particular word.

证明 为了证明由该定理得出的上界 K( x ),我们只需要证明存在一些不大于该界的 x描述。那么x 的最小描述可能比所演示的更短,但不会更长。

Proof To prove the upper bound K( x ) that follows from this theorem, we only need to show that there is some description of x that is not greater than the bound. Then the minimal description of x can be shorter than the one demonstrated, but not longer.

考虑以下对单词x的描述。设M为一台启动后立即停止的图灵机。该机器计算恒等函数 - 其输出与输入相同。x的描述就是〈M〉x 选择c作为长度〈M〉完成证明

Consider the following description of a word x . Let M be a Turing machine that halts immediately after starting. This machine computes the identity function—its output is identical to its input. The description of x is simply M x . Choosing c as the length of M completes the proof.

定理 6.24 显示了如何使用图灵机的输入来表示信息,如果使用图灵机的转换函数编写该信息,则需要更长的描述。这符合我们的直觉,即单词中包含的信息量不能明显大于其长度。同样,直觉告诉我们,单词xx所包含的信息并不显着大于x所包含的信息。下一个定理证实了这个直觉。

Theorem 6.24 shows how one can use the input to a Turing machine to represent information that would require a significantly longer description if it were written using the machine's transition function. This corresponds to our intuition that the amount of information contained in a word cannot be significantly greater than its length. Similarly, the intuition tells us that the information contained in the word xx is not significantly greater than the information contained in x . The next theorem confirms this intuition.

定理6.25

Theorem 6.25

c x [K( xx )≤K( x )+ c ]

c x [K( xx ) ≤ K( x ) + c ]

证明 考虑以下图灵机M,它期望输入形式为N , w ,其中N是图灵机, w是其输入字。

Proof Consider the following Turing machine M that expects input of the formN , w , where N is a Turing machine and w is its input word.

M = "对于输入单词N , w ,其中N是图灵机,w是单词:

M = "For an input word N , w , where N is a Turing machine and w is a word:

  1. 运行N for w直到停止并打印输出字s
  2. Run N for w until it stops and prints the output word s .
  3. 返回单词ss "。
  4. Return the word ss ".

xx描述为<M> d ( x )。回想一下d ( x ) 是x 的最小描述。xx描述的长度是 | 〈M〉| + | d ( x )|,即c +K ( x ),其中c是单词M 的长度。

The description of xx is M d ( x ). Recall that d ( x ) is the minimal description of x . The length of the description of xx is | M |+| d ( x )|, that is, c +K( x ), where c is the length of the word M .

现在我们将研究两个单词xy连接的描述复杂性与这些单词的单独复杂性的比较。定理 6.24 可能表明串联的复杂性至多等于各个复杂性的总和(加上固定常数),但组合两个描述的成本会导致更高的界限,如下一个定理所示。

We now examine how the description complexity of the concatenation of two words x and y relates to the individual complexities of these words. Theorem 6.24 might suggest that the complexity of the concatenation is at most equal to the sum of the individual complexities (plus a fixed constant), but the cost of combining two descriptions leads to a higher bound, as the next theorem shows.

定理6.26

Theorem 6.26

c x , y [K( xy ) ≤ 2K( x ) + K( y ) + c ]

c x , y [K( xy ) ≤ 2K( x ) + K( y ) + c ]

证明 我们构建了一个图灵机M,它将其输入分为两个单独的描述。第一个描述d ( x ) 的所有位都加倍并以字01终止,后面跟着第二个描述d ( y ),如图 6.22 之前的文本所述。一旦获得两个描述,就运行它们以生成单词xy,并生成输出xy

Proof We construct a Turing machine M that splits its input into two separate descriptions. All bits of the first description d ( x ) are duplicated and terminated by the word 01 , followed by the second description d ( y ), as described in the text preceding Figure 6.22. Once both descriptions are obtained, they are run to produce the words x and y , and the output xy is produced.

正如您所看到的,该描述xy的长度是x复杂度的两倍加上y复杂度,并辅以与描述M相对应的常数。所以这个总和是

As we can see, the length of this description xy is twice the complexity of x plus the complexity of y , supplemented by a constant corresponding to the description of M . So this sum is

2K( x )+K( y )+ c ,

2K( x ) + K( y ) + c ,

证明结束。

which completes the proof.

我们可以通过使用更有效的方法来标记两个描述之间的边界点来改进该定理产生的估计。例如,我们可以避免d ( x ) 的位重复。相反,我们在该单词前面加上长度为d ( x )的长度,写为双位二进制数,以将其与单词d ( x ) 本身区分开来。该描述仍然包含足够的信息,可以分为xy词描述,但现在其长度最多为

We can improve the estimate resulting from this theorem by using a more efficient method of marking the boundary point between two descriptions. For example, we can avoid duplicating the bits of d ( x ). Instead, we precede this word with the length d ( x ), written as a binary number with duplicated bits to distinguish it from the word d ( x ) itself. The description still contains enough information to be split into descriptions of words x and y , but now its length is at most

2 log 2 (K( x )) + K( x ) + K( y ) + c

2 log 2 (K( x )) + K( x ) + K( y ) + c .

上述估计还可以进一步改进。然而,正如我们将在问题 6.26 中看到的,不可能实现 K( x ) + K( y ) + c的估计。

The above estimate can be improved somewhat. However, as we will see in Problem 6.26, it is not possible to achieve an estimate of K( x ) + K( y ) + c .

定义的最优性

Optimality of definition

到目前为止,我们已经了解了描述复杂性的一些基本属性,并形成了一些基本的直觉。现在我们将仔细研究它的定义。

So far, we have learned some basic properties of descriptive complexity and developed some basic intuitions. Now we will take a closer look at its definition.

在使用算法定义复杂性的所有可能方法中,我们对 K( x ) 的定义本身就是最佳的。假设我们将通用描述语言视为任何可计算函数p : Σ * Σ *并定义给定p的x 的最小描述,我们将其写为d p ( x ),作为第一个单词s,使得p ( s ) = x按照字幕的标准顺序。因此,按字典顺序, s是x 的最短描述中的第一个。我们定义 K p ( x ) = | d p ( x )|。

Our definition of K( x ) is in its own way optimal among all possible ways of defining complexity in terms of algorithms. Suppose we consider the general description language as any computable function p : Σ * Σ * and define the minimal description of x with respect to p , which we will write d p ( x ), as the first word s such that p ( s ) = x in the standard string ordering. Thus s is lexicographically prime among the shortest descriptions of x . We define K p ( x ) = | d p ( x )|.

例如,考虑将 Python(二进制编码)等编程语言作为描述语言。那么d Python ( x ) 将是返回x的最小 Python 程序,而 K Python ( x ) 将是该最小程序的长度。

For example, consider a programming language such as Python (encoded in binary) as the description language. Then d Python ( x ) will be the smallest Python program that returns x , and K Python ( x ) will be the length of that smallest program.

下一个定理表明,任何这种描述语言并不比我们最初定义的图灵机和输入数据的语言更加简洁。

The next theorem shows that any description language of this kind is not significantly more concise than the language of Turing machines and the inputs we defined originally.

定理6.27

Theorem 6.27

对于任何描述语言p ,都有一个仅取决于p 的常数c,使得

For any language description p there exists a constant c depending only on p such that

x [K( x ) ≤ K p ( x ) + c ]。

x [K( x ) ≤ K p ( x ) + c ].

证明的概念 我们将使用Python来说明这个证明的思想。假设x在 Python 中有一个简短的描述。设M为可以解释 Python 的图灵机。我们将使用一个 Python 程序来生成x作为中的输入词。那么< M , w >就是x的描述,它只是一个比Python中x的描述大的常量分量。附加片段是机器M的长度,即 Python 解释器。

The Concept of the Proof We illustrate the idea of ​​this proof using Python. Suppose x has a short Python description. Let M be a Turing machine that can interpret Python. We use the Python program that generates x as input w . ThenM , w is a description of x that is only a constant term larger than the Python description of x . The extra bit is the length of M , the Python interpreter.

证明 采用任何描述语言p并考虑以下图灵机M。

Proof Take any description language p and consider the following Turing machine M .

M =“对于中的输入词:

M = "For input word in :

  1. 返回p ( w )”。
  2. Return p ( w )".

那么<M> dp ( x )是x的描述,长度最多比Kp ( x )一个固定常数。这个常数就是长度<M>

Then M d p ( x ) is a description of x whose length is greater than K p ( x ) by at most a fixed constant. This constant is the length of M .

不可压缩的词和随机性

Incompressible words and randomness

定理 6.24 表明,单词的最小描述永远不会比单词本身长很多。当然,有些单词的最小描述可能比单词本身短得多,只要其中包含的信息稀疏或冗余即可。但是,是否有任何单词缺少简短描述?换句话说,某些词的最小描述实际上和词本身一样长吗?我们将证明这样的词是存在的。这些词无法用比简单地写出来更简洁的方式来描述。

Theorem 6.24 shows that the minimal description of a word is never much longer than the word itself. Of course, there are words for which the minimal description can be much shorter than the word itself, provided that the information contained in the words is sparsely distributed or redundant. But are there words for which short descriptions are lacking? In other words, are the minimal descriptions of some words really as long as the words themselves? We will show that such words exist. These words cannot be described in any more concise way than by simply writing them out explicitly.

定义 6.28

Definition 6.28

x为一个词。我们说xc 可压缩的,如果

Let x be a word. We say that x is c-compressible if

K( x )≤| x | − c .

K( x ) ≤ | x | − c .

如果一个词x不是c可压缩的,我们就说它是c不可压缩的。如果单词x不可压缩 1,我们就说它是不可压缩的

If a word x is not c -compressible, we say that it is c -incompressible . If a word x is 1 -incompressible, we say that it is 1 -incompressible .

换句话说,如果字x的描述比其长度短c位,则x是可压缩。如果不是,则 x不可被c压缩。最后,如果x根本没有比它自身更短的描述,那么x是不可压缩的。我们将证明不可压缩词的存在,然后讨论它们有趣的属性。特别是,我们证明不可压缩的单词看起来就像通过随机抛硬币获得的单词。

In other words, if a word x has a description that is c bits shorter than its length, then x is c -compressible. If not, x is incompressible by c . Finally, if x has no description at all shorter than itself, then x is incompressible. We will show that incompressible words exist, and then discuss some interesting properties of them. In particular, we will show that incompressible words look like words obtained by randomly tossing a coin.

定理6.29

Theorem 6.29

存在各种长度的不可压缩单词。

There are incompressible words of any length.

证明的概念长度为n 的单词的数量大于长度小于n的单词的描述数量。每个描述最多可以描述一个词。由此可见,存在某个长度为n的单词,没有长度小于n的描述。这个词是不可压缩的。

Concept of the Proof The number of words of length n is greater than the number of descriptions of words of length less than n . Each description can describe at most one word. It follows that there is some word of length n that has no description of length less than n . This word is incompressible.

证明长度为n 的二进制字的数量为2n。每个描述都是一个二进制词,因此长度小于n的描述的数量最多是每个长度最多为n −1的词的数量之和,即

Proof The number of binary words of length n is 2n . Each description is a binary word, so the number of descriptions of length less than n is at most the sum of the number of words, each of which is at most n − 1 long, that is

短于n的描述数量小于长度n的单词数量。因此,至少有一个长度为n的字是不可压缩的。

The number of descriptions shorter than n is less than the number of words of length n . Thus, at least one word of length n is incompressible.

应用 6.30

Motion 6.30

至少 2 n − 2 nc + 1 + 1 个长度为n的字不可被c压缩。

At least 2n 2n c +1 + 1 words of length n are incompressible by c .

证明 我们将扩展定理 6.29 的证明。每个c 个可压缩单词最多有一个长度为n c的描述。这样的描述不超过 2 nc +1 − 1 个。因此,长度为n的 2 n 个单词中最多有 2 nc +1 − 1 个可以具有这样的描述。其余单词至少为 2 n − (2 nc +1 − 1) 并且不可被c压缩。

Proof We extend the proof of Theorem 6.29. Every c -compressible word has a description of length at most n c . There are no more than 2n c +1 1 such descriptions. Therefore, at most 2n c +1 1 out of 2n words of length n can have such descriptions. The remaining words are at least 2n (2n c +1 1) and are incompressible by c .

不可压缩词具有许多我们期望从随机选择的词中获得的属性。例如,我们可以证明任何长度为n的不可压缩字的 0 和 1 的数量大致相同,并且最大全零子字的长度约为 log 2 n,正如我们对该长度的随机字所期望的那样。证明这些定理会让我们对组合学和概率学过于深入,但我们将证明构成此类观察基础的定理。

Incompressible words have many properties that we would expect from randomly chosen words. For example, we can show that any incompressible word of length n has roughly the same number of zeros as ones, and that the length of the largest subword of all zeros is roughly log 2 n , just as we would expect from a random word of that length. Showing such theorems would take us too far into combinatorics and probability, but we will prove a theorem that forms the basis of such observations.

该定理表明,任何适用于“几乎所有”单词的可计算属性也适用于所有足够长的不可压缩单词。正如我们在第 0.2 节中提到的,单词属性只是一个函数f,它将单词映射到集合 {TRUE, FALSE} 中。如果随着n 的增加,长度为n的字符串中该属性为假的部分接近 0 ,我们就说该属性对几乎所有单词都成立。随机选择的长单词很可能满足可计算属性,该属性几乎适用于所有单词。因此,这些属性对于随机词和不可压缩词来说是常见的。

This theorem shows that any computable property that holds for “almost all” words holds for all sufficiently long incompressible words. As mentioned in Section 0.2, the property of words is simply a function f that maps words into the set {TRUE, FALSE}. We say that a property holds for almost all words if the fraction of sequences of length n for which it is false approaches 0 as n increases . A randomly chosen long word will most likely satisfy a computable property that holds for almost all words. Thus, such properties are common to both random words and incompressible words.

定理6.31

Theorem 6.31

f 是一个适用于几乎所有单词的可计算属性。对于任何b > 0,属性f不仅仅适用于关于b 的有限多个不可压缩词。

Let f be a computable property that holds for almost all words. For any b > 0 the property f does not hold only for finitely many incompressible words with b .

证明 M为以下算法。

Proof Let M be the following algorithm.

M =“对于输入字i,它是一个二进制整数:

M = "For input word i which is a binary integer:

  1. 找到标准(词典)词序中的第 i 个单词s ,其中f ( s ) = FALSE。
  2. Find the i -th word s in the standard (lexicographic) word ordering, where f ( s ) = FALSE.
  3. 返回s词。
  4. Return the s- word .

我们可以使用M来获取不具有f属性的单词的简短描述。对于任何这样的单词x,x为x在标准排序中不具有属性f的所有单词列表中的位置或索引 (即,按长度并在每个长度内按字典顺序排序)。那么< M , ix >就是对单词x的描述。该描述的长度是 |x | + c,其中c是M 的长度。由于只有少数单词不具有属性f,因此索引x很小,并且其描述也相应较短。

We can use M to obtain short descriptions of words that do not have the property f . For any such word x , let i x be the entry or index of x in the list of all words that do not have the property f in the standard ordering (that is, ordered by length and lexicographically within each length). Then M , i x is a description of word x . The length of this description is | i x | + c , where c is the length of M . Since very few words do not have the property f , the index x is small and its description is correspondingly short.

让我们假设某个固定数字b > 0。我们选择n ,使得对于长度为n或更小的单词的至多 1/2 b + c + 1部分,属性f不满足。所有足够大的n都将满足这个条件,因为几乎所有单词都满足f 。令x为长度为n且不满足属性f的单词。有 2 n +1 − 1 个长度为n或更小的单词,因此

Assume some fixed number b > 0. We choose n such that for at most 1/2 b + c + 1 of the words of length n or less, the property f does not hold. All sufficiently large n will satisfy this condition, since f holds for almost all words. Let x be a word of length n that does not satisfy the property f . There are 2n + 1 − 1 words of length n or less, so

由此可见|x | ≤ nbc,因此长度M , i x至多等于 ( nbc )+ c = nb,这意味着

It follows that | i x | ≤ nbc , so the length of M , i x is at most equal to ( nbc )+ c = nb , which implies that

K( x ) ≤ nb

K( x ) ≤ nb .

因此,任何不具有属性f的足够长的单词x都可以通过b进行压缩。因此,只有有限多个不满足属性f 的词不可被b压缩,这完成了定理的证明。

Thus, every sufficiently long word x that does not have the property f is compressible over b . Thus, only finitely many words that do not satisfy the property f are incompressible over b , which completes the proof of the theorem.

此时,提供一些不可压缩词的示例会很有用。然而,正如问题 6.23 所示,测度 K 是不可计算的。此外,没有算法可以普遍判定给定的单词是否不可压缩,正如我们将在问题 6.24 中讨论的那样。事实上,正如我们将在问题 6.25 中看到的,不可压缩词的无限子集是图灵可识别的。所以没有办法获得长的不可压缩词,即使找到一个词也没有办法判断它是否是不可压缩的。以下定理描述了一些几乎不可压缩的词,尽管它没有提供明确表示它们的方法。

At this point it would be useful to give some examples of incompressible words. However, as we will have to show in Problem 6.23, the measure K is not computable. Moreover, no algorithm can decide in general whether a given word is incompressible, which we will deal with in Problem 6.24. In fact, as we will see in Problem 6.25, no infinite subset of incompressible words is Turing recognizable. Thus, there is no method for obtaining long incompressible words, and there is no way to determine whether a word is incompressible even if we could find one. The following theorem describes some words that are nearly incompressible, although it does not give an explicit way to represent them.

定理6.32

Theorem 6.32

对于某个常数b,对于每个单词x ,单词x的最小描述d ( x )不能被b压缩。

For some constant b , for each word x , the minimal description d ( x ) of word x is incompressible by b .

证明 考虑以下图灵机M

Proof Consider the following Turing machine M :

M = "对于输入单词R , y ,其中R是图灵机,y是单词:

M = "For an input word R , y , where R is a Turing machine and y is a word:

  1. y运行R,如果其输出不是S , z 形式,则丢弃。
  2. Run R on y and reject if its output is not of the form S , z .
  3. 启动S代表z,然后停止并在磁带上显示本机的输出。”
  4. Start S for z and stop with this machine's output on tape."

b等于 | 〈M〉 | + 1. 我们将证明b满足定理的条件。相反,假设d ( x )对于某个单词x是b可压缩的。然后

Let b be equal to | M | + 1. We will show that this b satisfies the conditions of the theorem. Suppose conversely that d ( x ) is b -compressible for some word x . Then

| d ( d ( x ))| ≤ | d ( x )| - b .

| d ( d ( x ))| ≤ | d ( x )| − b .

然而,<M> d ( d ( x ) ) 是对单词x的描述其长度最多为

However, then M d ( d ( x )) is a description of a word x whose length is at most

| 〈M〉 | + | d ( d ( x ))| ≤ ( b − 1) + (| d ( x )| − b ) = | d ( x )| − 1.

| M | + | d ( d ( x ))| ≤ ( b − 1) + (| d ( x )| − b ) = | d ( x )| − 1.

x的这种描述比d ( x ) 短,这与d(x)是最短描述的假设相矛盾。

This description of x is shorter than d ( x ), which contradicts the assumption that d(x) is the shortest description.

练习

Exercises

6.1 给出一个真实编程语言(或其合理近似)的程序示例,该程序遵循递归定理的精神并自行编写。

6.1 Give an example of a program in a real programming language (or a reasonable approximation) that obeys the recursion theorem and prints itself.

6.2 证明MIN TM语言的任何无限子集都不是图灵可识别的。

6.2 Prove that any infinite subset of the language MIN TM is not Turing recognizable.

A 6.3 证明如果A T BB T C,则A T C

A 6.3 Prove that if A T B and B T C , then A T C .

6.4A TM ' = { M , w M是一台带有预言机的图灵机,M ATM接受w }。表明A TM ' 对于A TM是不可判定的。

6.4 Let A TM ' = { M , w : M is a Turing machine with an oracle and M ATM accepts w }. Prove that A TM ' is undecidable with respect to A TM .

A 6.5 句子x y [ x + y = y ] 是 Th( N ,+)的元素为什么是或为什么不是?对于句子x y [ x + y = x ] 你能说什么?

A 6.5 Is the sentencex y [ x + y = y ] an element of Th( N ,+)? Why or why not? What can be said about the sentencex y [ x + y = x ]?

任务

Tasks

6.6 描述两个不同的图灵机MN,使得对于任何输入M返回N N返回M

6.6 Describe two distinct Turing machines M and N such that for any input M returns N and N returns M .

6.7 在定点递归定理(定理 6.8)的变体中,令变换t为交换图灵机描述中状态q接受q拒绝的函数。给出变换t的常数点的示例。

6.7 In the fixed-point variant of the recursion theorem (Theorem 6.8), let the map t be a function that swaps the states q accept and q reject in the descriptions of Turing machines. Give an example of a fixed point of the map t .

*6.8 证明EQ TM m EQ TM

*6.8 Prove that EQ TM m EQ TM .

A 6.9 使用递归定理给出问题 5.28 中赖斯定理的另一种证明。

A 6.9 Use the recursion theorem to give an alternative proof of Rice's theorem in Problem 5.28.

A 6.10 提供句子的模型

A 6.10 Provide a model for the sentence

Φ eq = x [ R 1 ( x , x )]

Φ eq = x [ R 1 ( x , x )]

x , y [ R 1 ( x , y ) R 1 ( y , x )]

x , y [ R 1 ( x , y ) R 1 ( y , x )]

x , y ,z [( R 1 ( x , y ) R 1 ( y , z ) ) R 1 ( x , z ) ]。

x , y ,z [( R 1 ( x , y ) R 1 ( y , z)) R 1 ( x , z)].

*6.11Φ eq 的定义如问题 6.10 中所示。提供句子的模型

*6.11 Let Φ eq be defined as in Exercise 6.10. Give a model for the sentence

A 6.12 设 ( N , <) 为具有域N和“小于”关系的模型证明 Th( N , <) 是可判定的。

A 6.12 Let ( N , <) be a model with universe N and the relation "less than". Prove that Th( N , <) is decidable.

6.13 对于每个m > 1,令Z m = {0, 1, 2, …, m − 1} 并令F m = ( Z m ,+,×) 是一个模型,其宇宙为Z m,其关系为动作+ i × 计算的模m。证明对于每个m,理论 Th( F m ) 都是可判定的。

6.13 For every m > 1 let Z m = {0, 1, 2, …, m − 1} and let F m = ( Z m ,+,×) be a model whose universe is Z m and whose relations are the actions + and × evaluated modulo m . Show that for every m the theory Th( F m ) is decidable.

6.14 证明对于任何语言A和 B,都存在一种语言J使得AT JBT J

6.14 Prove that for any languages ​​A and  B there exists a language J such that AT J and BT J .

6.15 证明对于任何语言A都存在一种语言B ,使得AT BB T A

6.15 Prove that for any language A there exists a language B such that AT B and B T A .

*6.16 证明有两种语言A和 B是图灵不可比的——即A T BB T A

*6.16 Prove that there are two languages ​​A and  B that are Turing incomparable – that is, such that A T B and B T A .

*6.17A和 B是不相交的语言。如果A CB C,我们说语言C将 A和 B分开 。描述两种不相交的图灵可识别语言,它们不能被任何可判定语言分开。

*6.17 Let A and  B be disjoint languages. We say that a language C separates A and  B if A C and B C . Describe two Turing-disjoint languages ​​that are not separable by any decidable language.

6.18 证明EQ TM可以被语言A TM的图灵预言机识别。

6.18 Prove that EQ TM is recognizable by a Turing machine with an oracle for the language A TM .

6.19 在推论4.18中我们证明了所有语言的集合是不可数的。用这个结果来证明存在带有oracle A TM的图灵机无法识别的语言。

6.19 In Corollary 4.18 we showed that the set of all languages ​​is uncountable. Use this result to prove that there are languages ​​that are unrecognizable by a Turing machine with oracle A TM .

6.20 回顾第 5.2 节中定义的岗位适宜性问题以及相关的PCP语言。证明PCP对于A TM是可判定的。

6.20 Recall Post's correspondence problem, defined in Section 5.2, and its related language PCP . Show that PCP is decidable with respect to A TM .

6.21 展示如何在给定A TM的预言机的情况下计算单词 K( x ) 的计算复杂度。

6.21 Show how to calculate the computational complexity of the words K( x ), given an oracle for A TM .

6.22 使用问题 6.21 的结果给出一个可使用 oracle A TM计算的函数f,其中对于每个nf ( n ) 是长度为n的不可压缩字。

6.22 Use the result of Problem 6.21 to give a function f that is computable using the oracle A TM , where for each n , f ( n ) is an incompressible word of length n .

6.23 证明函数K( x ) 不可计算。

6.23 Prove that the function K( x ) is not computable.

6.24 证明不可压缩词集是不可判定的。

6.24 Prove that the set of incompressible words is undecidable.

6.25 证明不可压缩词集合不包含任何图灵可识别的无限子集。

6.25 Prove that the set of incompressible words does not contain any infinite Turing-recognizable subset.

*6.26 证明对于任何c都有一些词xy使得 K(xy) > K( x )+K( y )+ c

*6.26 Prove that for any c there exist some words x and y such that K(xy) > K( x )+K( y )+ c .

6.27S = { M M是图灵机,且L ( M ) = { M }}。证明SS都不是图灵可识别的。

6.27 Let S = { M : M is a Turing machine and L ( M ) = { M }}. Prove that neither S nor S is Turing recognizable.

6.28R N kk参数关系。如果我们可以给出一个带有k自由变量x 1 , …, x k 的公式Φ 使得对于所有a 1 , …, a kN , Φ ( a 1 , …, a k ) 恰好在a 1 , …, a kR时为真。证明以下每个关系在 Th( N ,+) 中都是可定义的。

6.28 Let R N k be a k -argument relation. We say that R is definable in Th( N ,+) if we can give a formula Φ with k free variables x 1 , …, x k , such that for all a 1 , …, a k N , Φ ( a 1 , …, a k ) is true exactly when a 1 , …, a k R . Prove that each of the following relations is definable in Th( N ,+).

R 0 = {0}

A a. R 0 = {0}

b.R 1 = {1}

b. R 1 = {1}

A c. R = = {( a , a ) : a N }

A c. R = = {( a , a ) : a N }

d. R < = {( a , b ) : a , b Na < b }

d. R < = {( a , b ) : a , b N and a < b }

精选解决方案

Selected solutions

6.3 假设M 1 B解析AM 2 C解析B。​我们将使用带有预言机M 3的图灵机,以便M 3 C解析A。机器M 3模拟M 1的操作。每次M 1向其预言机查询某个单词x时,机器M 3都会检查x 是否 B并将答案传递给M 1。由于机器M 3没有预言机B,无法直接执行此测试,因此它模拟M 2对于输入词x来获得答案。机器M 3可以直接从机器M 2获取查询的答案,因为两台机器使用相同的预言机,即C

6.3 Suppose M 1 B decides A , and M 2 C decides B . We use a Turing machine with an oracle M 3 , such that M 3 C decides A . Machine M 3 simulates the action of M 1 . Whenever M 1 queries its oracle for some word x , machine M 3 checks whether x B and passes the answer to M 1 . Since machine M 3 does not have the oracle B and cannot perform this test directly, it simulates M 2 for input word x to obtain the answer . Machine M 3 can directly obtain answers to M 2 's queries , since both machines use the same oracle, C .

6.5 句子x y [ x + y = y ] 是 Th( N ,+)的一个元素,因为它在宇宙N的关系 + 的标准解释下为真。回想一下,在本章中我们使用N = {0, 1, 2, …},因此我们可以使用x = 0。语句x y [ x + y = x ] 不是 Th( N ,+ ),因为在此模型中不成立。对于任意 x 值选择y = 1 会导致x + y = x不成立。

6.5 The sentence x y [ x + y = y ] is an element of Th( N ,+), since it is true under the standard interpretation of the relation + for universe N . Recall that in this chapter we use N = {0, 1, 2, …}, so we can use x = 0. The sentence x y [ x + y = x ] is not an element of Th( N ,+), since it is not true in this model. For any value x, choosing y = 1 implies that x + y = x is not satisfied.

6.9 为了隐式证明,让我们假设某个图灵机X解析属性P并且P满足赖斯定理的条件。这些条件之一表明存在图灵机A和 B使得A PB P。我们将使用A和 B来构造机器R

6.9 Suppose, for the sake of argument, that some Turing machine X decides a property P and that P satisfies the conditions of Rice's theorem. One of these conditions states that there exist Turing machines A and  B such that A P and B P . We use A and  B to construct a machine R :

R =“对于输入

R = "For input word in :

1.使用递归定理 获得您自己对R 〉的描述。

1. Obtain your own description of R using the recursion theorem.

2. 运行X得到〈R〉

2. Run X for R .

3. 如果X接受R ,则为w模拟B

3. If X accepts R , simulate B for w .

如果X拒绝R ,则模拟Aw

If X rejects R , simulate A for w ”.

如果R P,则X接受R L ( R ) = L ( B )。然而,<B> ∉P 它与<R>εP矛盾因为对于具有相同语言的图灵机来说,P的行为相同。如果R P ,我们将得出类似的矛盾。因此,我们原来的假设是错误的。任何满足赖斯定理条件的性质都是不可判定的。

If R P , then X accepts R and L ( R ) = L ( B ). However, B P , which contradicts R P , since P behaves the same for Turing machines that have the same language. An analogous contradiction occurs if R P . Hence, our original assumption is false. Any property that satisfies the conditions of Rice's theorem is undecidable.

6.10 语句Φ eq给出了等价关系的三个条件。模型 ( A , R 1 )是Φ eq的模型,其中A是任意全域,R 1 是A上的任意等价关系。例如,令A为整数Z的集合,并令R 1 = {( i , i ) : i Z }。

6.10 The sentence Φ eq states three conditions on an equivalence relation. The model ( A , R 1 ), where A is an arbitrary universe and R 1 an arbitrary equivalence relation over A , is a model of Φ eq . For example, let A be the set of integers Z and let R 1 = {( i , i ) : i Z }.

6.12 我们将 Th( N ,<) 简化为 Th( N ,+) ,我们已经证明了其可判定性。我们将展示如何将语言 ( N ,<) 上的句子Φ 1转换为语言 ( N ,+) 上的句子Φ 2,并在适当的模型中保持其正确或错误。我们将Φ 1中每次出现的i < j替换为Φ 2中的公式k [( i + k = j ) ( k + k k )] ,其中k每次都是一个不同的新变量。

6.12 We reduce Th( N ,<) to Th( N ,+), whose decidability we have already shown. We show how to transform the sentence Φ 1 over the language ( N ,<) into the sentence Φ 2 over the language ( N ,+), preserving truth or falsity in the appropriate models. Each occurrence of i < j in Φ 1 is replaced by the formula k [( i + k = j ) ( k + k k )] in Φ 2 , where k is a new, different variable each time.

语句Φ 2与Φ 1等效,因为“ i小于j ”意味着我们可以在 i 上添加一些非零值以获得j。根据 Th( N ,+) 分辨率算法的要求,将Φ 2转换为 prenex 形式需要一些额外的工作。新的存在量词移至句子开头。为此,量词必须经历句子中可能出现的布尔运算。量词可以通过操作移动而不做任何改变。遍历变为,反之亦然。因此Ø∃ k φ变成等价表达式k Ø ØØ" k Ø变成k Ø Ø

The sentence Φ 2 is equivalent to Φ 1 , since " i is less than j " means that we can add some nonzero value to i to get j . Transforming Φ 2 into prenex form, as required by the Th( N ,+) resolution algorithm, requires a bit of extra work. The new existential quantifiers are moved to the beginning of the sentence. To do this, the quantifiers must pass through the Boolean operations that may appear in the sentence. Quantifiers can be passed through the and operations without any change. Passing through ¬ turns into and vice versa. So ¬∃ k φ becomes equivalent to k ¬ φ , and ¬" k φ becomes k ¬ φ .

6.28 ( a ) R 0在 Th( N ,+) 中可通过Φ 0 ( x ) = y [ x + y = y ]定义。

6.28 ( a ) R 0 is definable in Th( N ,+) by Φ 0 ( x ) = y [ x + y = y ].

( c ) R =在 Th( N ,+) 中可通过Φ = ( u , v ) = x [ Φ 0 ( x ) x + u = v ]定义。

( c ) R = is definable in Th( N ,+) by Φ = ( u , v ) = x [ Φ 0 ( x ) x + u = v ].

7

时间复杂度

7

Time complexity

即使问题是可判定的,因此原则上可以通过计算解决,但如果解决方案需要过多的时间或内存,则在实践中也可能无法解决。在本书的最后一部分,我们介绍计算复杂性理论——研究解决计算问题所需的时间、内存或其他资源。我们将从时间复杂度开始。

Even if a problem is decidable, and therefore computationally solvable in principle, it may not be solvable in practice if the solution requires an excessive amount of time or memory. In this final part of the book, we will present the theory of computational complexity—the study of the time, memory, or other resources required to solve computational problems. We will begin with time complexity.

在本章中,我们的目标是介绍时间复杂度理论的基础知识。首先,我们将提出一种测量解决给定问题所需时间的方法。然后,我们将向您展示如何根据所需时间对问题进行分类。稍后,我们将讨论某些可解决的问题可能需要大量时间的可能性,并且我们将考虑如何确定这是否是我们正在处理的问题。

In this chapter, our goal is to present the basics of time complexity theory. First, we present a way to measure the time it takes to solve a given problem. Then, we show how problems can be classified according to the amount of time they require. Then, we discuss the possibility that some decidable problems may require an enormous amount of time, and we consider how to determine whether we are dealing with such a problem.

7.1

测量复杂性

7.1

Measuring Complexity

让我们从一个例子开始。让我们采用语言A = { 0 k 1 k : k ≥ 0}。我们知道A是可判定语言。单带图灵机需要多长时间才能决定A?我们将检查以下用于语言A 的单磁带机M 1 。我们将提供这台机器的底层描述,包括磁头在磁带上的实际运动,以便我们可以统计M 1在操作过程中使用的步数。

Let's start with an example. Take the language A = { 0 k 1 k : k ≥ 0}. We know that A is a decidable language. How long will a single-tape Turing machine take to decide A ? Let's examine the following single-tape Turing machine M 1 for the language A . We'll give a low-level description of this machine, including the actual movements of the head on the tape, so that we can count the number of steps M 1 uses during its operation.

M 1 =“对于输入字:

M 1 = "For input word in :

  1. 浏览磁带,如果发现1右边的0 ,则丢弃
  2. Scan the tape and reject if a 0 is found to the right of a 1 .
  3. 重复此操作,直到磁带上保留有 0 和 1:
  4. Repeat until both zeros and ones remain on the tape:
  5. 翻阅磁带,一次划掉一个0和一个1
  6. Scan through the tape, crossing out one 0 and one 1 at a time .
  7. 如果划掉所有零后仍然存在零,或者划掉所有零后还剩下任何零,则丢弃。否则,如果磁带上没有留下任何零或一,则接受。”
  8. If zeros are still present after all ones have been crossed out, or if any ones remain after all zeros have been crossed out, reject . Otherwise, if no ones or zeros remain on the tape, accept ”.

我们将分析机器M 1决定A的算法,以确定它必须使用多少时间。首先,我们将介绍一些对此有用的术语和符号。

We will analyze the algorithm for a machine M 1 deciding A , to determine how much time it must spend. We first introduce some terminology and notation useful for this purpose.

算法用于特定输入的步骤数可能取决于许多参数。例如,如果输入是图,则步数可以取决于该图中的顶点数、边数和顶点的最大度,或者这些和/或其他因素的某种组合。为简单起见,我们将计算算法执行时间作为表示输入的单词长度的函数,并且不会考虑任何其他参数。在最坏情况分析(我们将在这里考虑的变体)中,我们将考虑给定长度的所有输入的最长执行时间。在平均情况分析中,我们考虑给定长度的输入数据的所有执行时间的平均值。

The number of steps an algorithm uses for a given input can depend on a number of parameters. For example, if the input is a graph, then the number of steps can depend on the number of vertices, the number of edges, and the maximum degree of a vertex in that gaffe, or some combination of these and/or other factors. For simplicity, we will calculate the algorithm's execution time as a function of the length of the word representing the input and will not consider any other parameters. In worst-case analysis , the case we will consider here, we consider the longest execution time for all inputs of a specified length. In average-case analysis, we consider the average of all execution times for inputs of a specified length.

定义 7.1

Definition 7.1

M为确定性图灵机,对每个输入都停止。M 的运行时间时间复杂度 是函数f : →  N,其中f ( n ) 是M对长度为n的任何输入使用的最大步数。如果f ( n ) 是M的运行时间,那么我们说M在时间f ( n ) 运行,并且M是在时间f ( n )的图灵机。我们习惯上用n来表示输入数据的长度。

Let M be a deterministic Turing machine halting for every input. The running time or time complexity of M is a function f : →  N , where f ( n ) is the maximum number of steps that M takes for any input of length n . If f ( n ) is the running time of M , then we say that M runs in time f ( n ) and that M is a Turing machine of time f ( n ). By convention, we use n to represent the length of the input.

大写O和小写O的表示法

Big O and Little O Notation

算法的确切运行时间通常用非常复杂的表达式来描述,而我们通常只是估计它。在一种称为渐近分析的便捷估计方法中,我们尝试了解大型输入数据的算法的运行时间。为此,我们仅考虑给出算法运行时间的表达式中最重要的分量,忽略该分量的系数和所有不太重要的分量,因为最重要的分量在大型输入数据中占主导地位。

The exact running time of an algorithm is often described by a very complex expression, and we usually only estimate it. In one convenient estimation method, called asymptotic analysis , we try to find the running time of the algorithm for large inputs. We do this by considering only the most significant terms of the expression giving the running time of the algorithm, ignoring both the coefficient of this term and all less significant terms, since the most significant term dominates for large inputs.

例如,函数f ( n ) = 6 n 3 + 2 n 2 + 20 n + 45 包含四项,最重要(最高次数)为 6 n 3。忽略因子 6,我们说f渐近有界于n 3。描述这种关系的渐近O表示法是f ( n ) = O ( n3 )。我们将在下面的定义中形式化这个符号。令R +为非负实数集合。

For example, the function f ( n ) = 6 n 3 + 2 n 2 + 20 n + 45 contains four terms, with the most significant (of the highest degree) being 6 n 3 . Neglecting the factor 6, we say that f is asymptotically bounded by n 3 . The asymptotic notation or big O notation describing such a relation is f ( n ) = O ( n 3 ). We formalize this notation in the following definition. Let R + be the set of nonnegative real numbers.

定义 7.2

Definition 7.2

fgf , g : N R +的函数。如果存在正整数cn 0且对于每个整数nn 0,我们称f ( n ) = O ( g ( n ))

Let f and g be functions f , g : N R + . We say that f ( n ) = O ( g ( n )) if there exist positive integers c and n 0 such that for every integer nn 0 ,

f ( n ) ≤cg ( n )

f ( n ) ≤ c g ( n ).

f ( n ) = O ( g ( n )) 时,我们说g ( n ) 是f ( n )的上界,或者更准确地说,g ( n ) 是f ( n )的渐近上界,这凸显了我们忽略常数系数的事实。

When f ( n ) = O ( g ( n )), then we say that g ( n ) is an upper bound for f ( n ) or more precisely that g ( n ) is an asymptotic upper bound for f ( n ), which emphasizes the fact that we neglect the constant coefficients.

直观上,f ( n ) = O ( g ( n )) 意味着f小于或等于g,只要我们忽略常数因子的差异。我们可以将O表示法视为省略常量的表示。在实践中,我们遇到的大多数函数f都有一个明显的最高有效项h。在这种情况下,我们写成f ( n ) = O ( g ( n )),其中g是h的项,不带系数。

Intuitively, f ( n ) = O ( g ( n )) means that f is less than or equal to g , provided we ignore differences by a constant factor. We can think of the notation O as a representation of the omitted constant. In practice, most functions f that we will encounter have an obvious most significant component h . In such a case, we write f ( n ) = O ( g ( n )), where g is the component of h without a coefficient.

7.3

Example 7.3

f 1 ( n ) 为 5 n 3 +2 n 2 +22 n +6的函数。选择最高次项 5 n 3并忽略其因子 5,我们得到f 1 ( n ) = O ( n 3 )。

Let f 1 ( n ) be a function of 5 n 3 + 2 n 2 + 22 n + 6. Choosing the term of highest degree 5 n 3 and neglecting its coefficient 5, we obtain f 1 ( n ) = O ( n 3 ).

让我们验证一下这个结果是否满足形式化定义的条件。我们将通过取c等于 6 和n 0等于 10 来实现这一点。然后 5 n 3 +2 n 2 +22 n +6 ≤ 6 n 3对于所有 ≥ 10。

Let us verify that this result satisfies the formal definition. We will achieve this by setting c equal to 6 and n 0 equal to 10. Then 5 n 3 +2 n 2 +22 n +6 ≤ 6 n 3 for all ≥ 10.

另外,f 1 ( n ) = O ( n 4 ),因为n 4大于n 3 ,因此也是f 1的渐近上限。

Additionally, f 1 ( n ) = O ( n 4 ), since n 4 is greater than n 3 , and therefore it is also an asymptotic upper bound for f 1 .

另一方面,f 1 ( n ) 不是O ( n 2 )。无论分配给cn 0的值如何,在这种情况下定义仍然不满足。

On the other hand, f 1 ( n ) is not O ( n 2 ). Regardless of the values ​​assigned to c and n 0 , in this case the definition remains unsatisfied.

7.4

Example 7.4

大O表示法以一种特殊的方式与对数相互作用。通常,在使用对数时,我们需要提供底数,例如x = log 2 n。在这种情况下,基数为 2 表示该等式等价于等式 2 x = n。更改基数b的值会按常数因子更改 log b n的值,该因子由恒等式 log b n = log n / log 2 b得出。因此,在写f ( n ) = O(log n ) 时,不再需要提供依据,因为我们无论如何都忽略了常数因子。

Big O notation works in a special way with logarithms. Usually, when we use logarithms, we need to specify a base, for example x = log 2 n . The base 2 in this case indicates that this equality is equivalent to the equality 2 x = n . Changing the value of the base b changes the value of log b n by a constant factor, which follows from the identity log b n = log n / log 2 b . Therefore, when we write f ( n ) = O(log n ), it is no longer necessary to specify a base, since we are omitting the constant factors anyway.

f 2 ( n ) 为函数 3 n log 2 n + 5 n log 2 log 2 n + 2。在这种情况下,我们得到f 2 ( n ) = O ( n log n ),因为 log n支配 log log n

Let f 2 ( n ) be a function of 3 n log 2 n + 5 n log 2 log 2 n + 2. In this case we get f 2 ( n ) = O ( n log n ), since log n dominates log log n .

大写O表示法也出现在算术表达式中,例如f ( n ) = O ( n 2 )+ O ( n )。在这种情况下,符号O的每次出现代表不同的省略常数。由于O ( n2 ) 项支配O ( n ),因此该表达式等价于f ( n ) = O ( n2 )。当符号O出现在指数中时,如表达式f ( n ) = 2O ( n )中所示,同样的推理也适用。该表达式表示某个常数c2cn 形式的上限。

Big O notation also appears in arithmetic expressions, such as f ( n ) = O ( n 2 ) + O ( n ). In this case, each occurrence of the symbol O represents a different omitted constant. Since the O ( n 2 ) term dominates O ( n ), this expression is equivalent to f ( n ) = O ( n 2 ). The same reasoning applies when the symbol O appears in the exponent, as in the expression f ( n ) = 2 O( n ) . This expression represents an upper bound of the form 2 cn for some constant c .

有时我们可能会遇到f ( n )=2O ( log n )形式的表达式。使用恒等式n = 2 log 2 n,因此nc = 2 c log 2 n,我们可以看到 2 O ( log n )表示某些c的n c的上限。表达式n O(1)以不同的方式暗示相同的限制,因为表达式O (1) 表示一个永远不会大于某个常数的值。

Sometimes we may encounter expressions of the form f ( n ) = 2 O( log n ) . Using the identities n = 2 log 2 n , and hence n c = 2 c log 2 n , we can see that 2 O( log n ) represents an upper bound on n c for some c . The expression n O(1) represents the same bound in a different way, since the expression O (1) represents a value that is never greater than some constant.

c大于 0 时,我们经常会导出n c形式的约束。此类约束称为多项式约束。 2 ( )形式的约束称为指数约束,其中 δ 是大于 0 的实数

We will often derive constraints of the form n c for c greater than 0. Such constraints are called polynomial constraints . Constraints of the form 2 ( n δ ) are called exponential constraints , where δ is a real number greater than 0.

大写 O 表示法有一个附带的小写 o 表示法。大O表示法指出某个函数渐近大于另一个函数。为了表示某个函数渐近小于另一个函数,我们使用小符号。大写O和小写o符号之间的区别类似于 ≤ 和 < 之间的区别。

Big O notation has a companion notation, little o . Big O notation states that some function is asymptotically no greater than another. To say that some function is asymptotically less than another, we use little o notation. The difference between big O and little o notations is analogous to the difference between ≤ and <.

定义 7.5

Definition 7.5

fgf , g : N R +的函数。我们说f ( n ) = o ( g ( n )) 如果

Let f and g be functions f , g : N R + . We say that f ( n ) = o ( g ( n )), if

换句话说,f ( n ) = o ( g ( n )) 意味着对于任何实数c > 0,存在一个数n 0使得f ( n ) < c g ( n ) 对于所有nn 0

In other words, f ( n ) = o( g ( n )) means that for any real number c > 0 there exists a number n 0 such that f ( n ) < c g ( n ) for all nn 0 .

7.6

Example 7.6

可以轻松检查以下观察结果。

The following observations can be easily checked.

  1. n = o( n )。
  2. n = o( n ).
  3. n = on对数n)。
  4. n = o ( n log log n ).
  5. n log log n = o ( n log n )。
  6. n log log n = o ( n log n ).
  7. n log n = o ( n 2 )。
  8. n log n = o ( n 2 ).
  9. n 2 = o( n 3 )。
  10. n2 = o( n3 ) .

然而,等式f ( n ) = o ( f ( n ))永远不成立。

However, the equality f ( n ) = o ( f ( n )) never holds .

算法分析

Algorithm Analysis

现在我们将分析针对语言A = { 0 k 1 k : k ≥ 0} 提出的 TM 算法。为了方便起见,我们在这里重复这个算法。

We now analyze the TM algorithm that we presented for the language A = { 0 k 1 k : k ≥ 0}. For convenience, we repeat this algorithm here.

M 1 =“对于输入字:

M 1 = "For input word in :

  1. 浏览磁带,如果发现1右边的0 ,则丢弃
  2. Scan the tape and reject if a 0 is found to the right of a 1 .
  3. 重复此操作,直到磁带上保留有 0 和 1:
  4. Repeat until both zeros and ones remain on the tape:
  5. 翻阅磁带,一次划掉一个0和一个1
  6. Scan through the tape, crossing out one 0 and one 1 at a time .
  7. 如果划掉所有零后仍然存在零,或者划掉所有零后仍然存在任何零,则丢弃。否则,如果磁带上没有留下任何零或一,则接受。”
  8. If zeros are still present after all ones have been crossed out, or if any ones remain after all zeros have been crossed out, reject. Otherwise, if no ones or zeros remain on the tape, accept ."

为了能够分析M 1的操作,我们必须分别考虑四个步骤中的每一个。在步骤 1 中,机器查看整个磁带以检查输入字是否为 0 * 1 *。此操作需要n个头步骤。正如我们之前提到的,我们通常使用n来表示输入数据的长度。将磁头移回磁带开头还需要n个步骤。这一步我们总共执行了2n次操作。在大写O表示法中,我们将写出此步骤使用O ( n ) 操作。请注意,在机器的描述中我们没有提到缩回头部。使用渐近约束允许我们省略机器描述的细节,这些细节最多会改变操作时间一个常数因子。

To analyze the operation of M 1 , we need to consider each of the four steps separately. In step 1, the machine scans the entire tape to see if the input word is of the form 0 * 1 * . This operation requires n head steps. As mentioned earlier, we will typically use n to refer to the length of the input data. Moving the head back to the beginning of the tape requires another n steps. In total, we have performed 2n operations in this step . In big O notation, we will write that this step uses O ( n ) operations. Note that we did not mention moving the head back in our description of the machine. Using asymptotic constraints allows us to ignore details of the machine description that change the running time by at most a constant factor.

在步骤 2 和 3 中,机器从磁带的开头移动到结尾,一次划掉一个零和一个一。每一遍需要O ( n ) 步骤。由于为每个通道绘制两个符号,因此我们最多有n /2 个通道。步骤 2 和 3 消耗的总时间为 ( n /2) O ( n ) = O ( n 2 ) 次操作。

In steps 2 and 3, the machine strikes out one zero and one one at a time, traveling from the beginning to the end of the tape. Each pass requires O ( n ) steps. Since two symbols are struck out in each pass, we have at most n /2 passes. The total time taken by steps 2 and 3 is ( n /2) O ( n ) = O ( n 2 ) operations.

在第4步中,机器扫描一次磁带以确定是否接受或拒绝该单词。该阶段所需时间最多为O ( n )。

In step 4, the machine scans the tape once to see whether to accept or reject the word. The time required for this phase is at most O ( n ).

机器M 1处理长度为n的输入字所需的总时间为O ( n ) + O ( n 2 ) + O ( n ) 或O ( n 2 )。也就是说它的运行时间是O ( n2 ),这就完成了这台机器的时间复杂度的分析。

The total time it takes for machine M 1 to process an input word of length n is O ( n ) + O ( n 2 ) + O ( n ), or O ( n 2 ). In other words, its running time is O ( n 2 ), which completes the time complexity analysis of this machine.

我们现在将定义一个符号来根据语言的时间要求对语言进行分类。

We now define a notation that allows languages ​​to be classified according to their timing requirements.

定义 7.7

Definition 7.7

t : N R + 为函数。我们将时间复杂度类 TIME(t(n))定义为图灵机在时间O ( t ( n )) 内可判定的所有语言的集合。

Let t : N R + be a function. We define the time complexity class TIME(t(n)) as the set of all languages ​​decidable by a Turing machine in time O ( t ( n )).

让我们回忆一下语言A = { 0 k 1 k : k ≥ 0}。上述分析表明,A TIME( n 2 ),因为M 1在时间O ( n 2 ) 内解析了语言A,而 TIME( n 2 ) 包含了在时间O ( n 2 )内可以解析的所有语言。

Recall the language A = { 0 k 1 k : k ≥ 0}. The above analysis shows that A TIME( n 2 ), since M 1 resolves the language A in time O ( n 2 ), and TIME( n 2 ) contains all languages ​​that can be resolved in time O ( n 2 ).

是否有一台机器可以更快(渐近)解析语言A?换句话说,对于某个函数t ( n ) = o ( n 2 ), A是否属于 TIME( t ( n )) ?我们可以通过在步骤 3 的每次传递中绘制两个 0 和两个 1 而不是一个来缩短运行时间,这会将传递次数减半。然而,这只会将运行时间提高 2 倍,不会影响渐近运行时间限制。下面的M 2机器使用不同的方法来渐近更快地解析语言A。它表明A TIME( n log n )。

Is there a machine that resolves A faster (asymptotically) ? In other words, does A belong to TIME( t ( n )) for some function t ( n ) = o ( n 2 )? We can improve the running time by crossing out two zeros and two ones in each pass of step 3 instead of one, which halves the number of passes. However, this improves the running time only by a factor of 2 and does not affect the asymptotic bound on the running time. The following machine M 2 uses a different method to resolve A asymptotically faster. It shows that A TIME( n log n ).

M 2 =“对于输入字:

M 2 = "For input word in :

  1. 查看磁带,如果某个数字的右侧有任何零,则将其丢弃。
  2. Scan the tape and discard if any zero is to the right of a certain one.
  3. 重复直到磁带上留下一些零和一:
  4. Repeat until there are some zeros and ones left on the tape:
  5. 浏览磁带,检查剩余的 0 和 1 的数量是偶数还是奇数。如果是奇数,则丢弃
  6. Review the tape to see if the number of ones and zeros remaining is even or odd. If odd, discard .
  7. 再次检查磁带,从第一个开始每隔一个 0 划掉,然后从第一个开始每隔一个 1 划掉。
  8. Go through the tape again, crossing out every other zero, starting with the first, and then crossing out every other one, starting with the first.
  9. 如果磁带上没有留下任何零或一,请接受。否则,丢弃。”
  10. If there are no zeros or ones left on the tape, accept . Otherwise, reject ”.

在开始分析M 2之前,我们先确保该机器确实解析了A。在步骤 4 中执行的每一遍中,剩余零的总数减半,并且丢弃任何剩余部分。因此,如果我们从 13 个零开始,执行完步骤 4 一次后,就只剩下 6 个。重复此步骤后,我们仍然会得到 3 个零,然后是 1,最后是 0。这一步对 1 的数量具有相同的效果。

Before we begin analyzing M 2 , let's make sure that this machine actually resolves A . On each pass in Step 4, the total number of remaining zeros is halved, and any remainder is discarded. So if we start with 13 zeros, after performing Step 4 once, only 6 will remain. After performing Step 4 once more, there will be 3 zeros left, then a 1, and finally a 0. This step has the same effect on the number of ones.

在步骤 3 的每次执行中,我们都会检查 0 和 1 的数量的奇偶校验。再次假设我们从 13 个 0 和 13 个 1 开始。第一次执行步骤 3 会找到奇数个 0(因为 13 是奇数)和奇数个 1。在后续版本中,出现偶数 (6),然后出现奇数 (3),然后出现奇数 (1)。由于步骤 2 中指定的循环重复条件,我们不会对 0 个零或一个执行此步骤。对于找到的奇偶校验字符串(奇数、偶数、奇数、奇数),如果我们将偶数结果替换为 0,奇数结果替换为并以相反的顺序写入字符串,我们将得到 1101 - 数字 13 的二进制形式,即运算开始时的 0 和 1 的数量。该奇偶校验序列始终以相反的顺序给出零(一)数量的二进制形式。

In each iteration of step 3, we check for evenness in the number of zeros and ones. Again, suppose we start with 13 zeros and 13 ones. The first iteration of step 3 finds an odd number of zeros (since 13 is odd) and an odd number of ones. In subsequent iterations, we find an even number (6), then an odd number (3), and then an odd number (1). We do not do this step for 0 zeros or ones because of the looping condition specified in step 2. For the found parity sequence (odd, even, odd, odd), if we replace the even results with zeros and the odd results with ones and write the sequence in reverse order, we get 1101, the binary form of 13, the number of zeros and ones at the beginning of the operation. This parity sequence always produces the binary form of the number of zeros (ones) in reverse order.

当我们在步骤 3 中检查剩余的 0 和 1 的总数是否为偶数时,我们实质上是在检查 0 的数量和 1 的数量的奇偶性。如果所有奇偶校验都匹配,则零和一的二进制形式也匹配,因此这两个数字相等。

When we check in Step 3 whether the total number of remaining zeros and ones is even, we are in fact checking for the evenness of the number of zeros and the evenness of the number of ones. If all the evens match, then the binary forms of the zeros and ones match, so the two numbers are equal.

分析M 2的运行时间,我们可以看到每一步执行一次需要O ( n )时间。然后我们将确定每一项将被执行的次数。步骤1和5各只执行一次,总共花费O ( n )时间。在步骤 4 中,每次传递至少绘制一半的 0 和 1,因此在全部绘制之前最多可以进行 1 + log 2 n迭代。因此,步骤2、3和4的总运行时间为(1 + log 2 n ) O ( n ),即O ( n log n )。机器M 2的运行时间为O ( n )+ O ( nlogn ) =O ( nlogn )

By analyzing the running time of M 2 , we can see that a single execution of each step takes time O ( n ). Next, we determine the number of times each is executed. Steps 1 and 5 are executed only once, which takes a total of O ( n ). In step 4, at least half of the zeros and ones are crossed out in each pass, so there can be at most 1 + log 2 n iterations before all of them are crossed out. Thus, the total running time of steps 2, 3, and 4 is (1 + log 2 n ) O ( n ), or O ( n log n ). The running time of M 2 is O ( n ) + O ( n log n ) = O( n log n ).

我们之前证明了A TIME( n 2 ),但现在我们有了更好的约束——具体来说,A TIME( n log n )。在单带图灵机上无法进一步改善该结果。事实上,任何可以在单带图灵机上在o ( n log n ) 时间内解析的语言都是正则语言,如问题 7.49 所示。

We showed earlier that A TIME( n 2 ), but now we have a better bound—namely, A TIME( n log n ). This result cannot be improved any further on a single-tape Turing machine. In fact, any language that can be decided in time o ( n log n ) on a single-tape Turing machine is a regular language, as we will have to show in Problem 7.49.

如果图灵机有第二盘磁带,我们就可以在 O( n ) 时间(也称为线性时间)内解析语言A。下面的两带M 3机器在线性时间内解析语言A。M 3机器的工作方式与以前的 A 语言解析器不同,它只是将零复制到第二个磁带上,然后将它们与这些进行匹配。

We could resolve language A in O( n ) time (also called linear time ) if the Turing machine had a second tape. The following two-tape machine M 3 resolves language A in linear time. The M 3 works differently than previous machines that resolve language A. It simply copies the zeros onto its second tape and then matches them with ones.

M 3 =“对于输入字:

M 3 = "For input word in :

  1. 浏览磁带 1,如果发现1右侧有0 ,则丢弃
  2. Scan tape 1 and discard if you find a 0 to the right of 1 .
  3. 逐步遍历磁带 1 上的零,直到出现第一个零。同时将零复制到磁带 2。
  4. Step through the zeros on tape 1 until the first one occurs. Simultaneously copy the zeros to tape 2.
  5. 跟踪磁带 1 上的 1 到输入字的末尾。对于磁带 1 上的每个 1 读取,请在磁带 2 上划掉一个零。如果在读取所有 1 之前划掉所有 0,请丢弃.
  6. Scan through the ones on tape 1 to the end of the input word. For each one read on tape 1, cross out one zero on tape 2. If you cross out all the zeros before reading all the ones, discard .
  7. 如果所有零均已删除,则接受。如果剩下任何零,则丢弃。”
  8. If all zeros have been crossed out, accept . If any zeros remain, reject ."

这台机器很容易分析。这四个步骤中的每一步都使用O ( n ) 运算,因此总运行时间为O ( n ),即线性时间。请注意,此运行时间是尽可能短的,因为我们只需要n步来读取输入字。

This machine is easy to analyze. Each of the four steps uses O ( n ) operations, so the total running time is O ( n ), which is linear time. Note that this running time is the smallest possible, since we need n steps just to read the input word.

让我们尝试总结一下我们所展示的关于语言A的时间复杂度,解析语言 A 所需的时间量。我们构建了一个单带图灵机M 1 ,它在O ( n2 )时间内解析A ,以及更快的单磁带机,可以在O ( nlogn )时间内解析A。问题 7.49 的解决方案表明,没有单带图灵机可以更快地完成此任务。然后我们提出了一个两带机M 3在O ( n )时间内解析A。因此, A在单磁带机上的时间复杂度为O ( n log n ),在两磁带机上为 O ( n )。请注意,语言A的复杂性取决于所选的计算模型。

Let's try to summarize what we have shown about the time complexity of A , that is, the amount of time required to decide A. We have built a single-tape Turing machine M 1 that decides A in time O ( n 2 ), and a faster single-tape Turing machine that decides A in time O ( n log n ). From the solution to Problem 7.49, it follows that no single-tape Turing machine can do this faster. We have then shown a two-tape Turing machine M 3 that decides A in time O ( n ). Thus, the time complexity of A on a single-tape machine is O ( n log n ), and on a two-tape machine it is O ( n ). Note that the complexity of A depends on the chosen model of computation.

这些考虑凸显了复杂性理论和可计算性理论之间的重要区别。在后者中,我们可以从丘奇-图灵假设得出结论,所有合理的计算模型都是等效的 - 换句话说,它们解析同一类语言。在复杂性理论中,模型的选择会影响语言的时间复杂性。在一个模型中可以在线性时间内判定的语言在另一种模型中不一定可以在线性时间内判定。

These considerations draw attention to an important difference between complexity theory and computability theory. In the latter, we can conclude from the Church–Turing hypothesis that all reasonable models of computation are equivalent—in other words, they resolve the same class of languages. In complexity theory, the choice of model affects the time complexity of a language. Languages ​​that are decidable in linear time in one model are not necessarily decidable in linear time in another.

在复杂性理论中,我们根据计算问题的时间复杂度对其进行分类。但是我们使用哪种模型来测量时间呢?同一语言在不同模型中可能有不同的时间要求。

In complexity theory, we classify computational problems according to their time complexity. But which model do we use to measure time? The same language can have different time requirements in different models.

幸运的是,对于典型的确定性模型,时间要求没有显着差异。因此,如果我们的分类系统对复杂性的微小差异不太敏感,那么确定性模型的选择就不会太重要。我们将在以下小节中更详细地讨论这个问题。

Fortunately, the time requirements do not differ significantly for typical deterministic models. Thus, if our classification system is not too sensitive to small differences in complexity, the choice of a deterministic model will not be overly important. We will discuss this issue in more detail in the following subsections.

模型复杂度之间的关系

Relationships between model complexities

在本节中,我们将讨论计算模型的选择如何影响语言的时间复杂度。我们将考虑三种模型:单带图灵机、多带图灵机和非确定性图灵机。

In this section, we will discuss how the choice of computation model can affect the time complexity of languages. We will consider three models: the single-tape Turing machine, the multi-tape Turing machine, and the nondeterministic Turing machine.

定理7.8

Theorem 7.8

t ( n ) 为满足t ( n ) ≥ n的函数。那么对于每一个运行时间为t ( n )的多带图灵机,都存在一个等价的运行时间为O ( t 2 ( n ))的单带图灵机。

Let t ( n ) be a function such that t ( n ) ≥ n . Then for every multi-tape Turing machine of running time t ( n ), there exists an equivalent single-tape Turing machine of running time O ( t 2 ( n )).

证明的概念 证明这个定理的想法非常简单。回想一下,在定理 3.13 中,我们展示了如何将任何多磁带图灵机转换为模拟它的单磁带机。我们将分析此模拟以确定它需要多少额外时间。在单磁带机上最多需要O ( t ( n )) 个步骤。因此,总仿真时间为O ( t2 ( n ) ) 步骤。

Concept of Proof The idea of ​​the proof of this theorem is quite simple. Recall that in Theorem 3.13 we showed how to transform any multitape Turing machine into a single-tape Turing machine simulating it. Let us analyze this simulation to determine how much extra time it requires. We will show that to simulate each step of the multitape machine we need at most O ( t ( n )) steps on the single-tape machine. Thus, the total simulation time is O ( t 2 ( n )) steps.

证明 M是在时间t ( n )运行的k带图灵机。我们将构建一个运行时间为O ( t2 ( n ))单带图灵机S。

Proof Let M be a k -tape Turing machine running in time t ( n ). We construct a single-tape Turing machine S that runs in time O ( t 2 ( n )).

机器S通过模拟机器M进行操作,如定理 3.13 中所述。回想一下,该模拟涉及S使用其单个磁带来表示机器M的所有k 个磁带的内容。这些磁带按顺序写入,在适当的单元中标记M机头的位置。

Machine S operates by simulating machine M as described in Theorem 3.13. Recall that this simulation consists of S using its single tape to represent the contents of all k tapes of machine M . These tapes are written out sequentially, with the positions of the heads of machine M marked in the appropriate cells.

机器S首先以代表机器M的所有磁带的形式存储其磁带,然后模拟机器M的步骤。为了模拟一个步骤,S查看其磁带上存储的所有信息,以确定位于机器M磁头下的符号。然后,S从头到尾重新运行磁带,更新其内容和磁头位置。如果M个磁头之一在其磁带先前未使用的部分上向右移动,则S必须增加分配给该磁带的空间量。它通过将自己磁带的一些内容向右移动一个单元格来实现这一点。

Machine S begins by writing its tape as a representation of all of machine M ' s tapes , and then simulates the steps of machine M . To simulate one step, S scans through all of the information on its tape to determine the symbols under M 's heads . S then scans the tape again from beginning to end, updating its contents and the positions of the heads. If any of M 's heads moves right onto a previously unused part of its tape, S must increase the amount of space allocated to that tape. It does this by shifting part of its own tape's contents one cell to the right.

现在让我们分析一下这个模拟。对于机器 M 的每个步骤机器S都会两次穿过其胶带的已用部分。第一个允许您获取确定下一步移动所需的信息,而在第二个中则执行移动。磁带S的已使用部分的长度决定了观看它所花费的时间,因此我们需要为这个长度设置一个上限。为了实现这一点,我们可以将机器M的所有k 个磁带的有效部分的长度相加。使用的每个部分的长度至多为t ( n ),因为如果磁头在每一步中向右移动,则M在t ( n ) 步中使用t ( n ) 个磁带单元;如果头部向左移动,M使用的单元就会更少。因此查看S带的活动部分需要O ( t ( n )) 个步骤。

Let us now analyze this simulation. For each step of machine M, machine S makes two passes through the used portion of its tape. The first passes provide the information necessary to determine the next move, and the second passes actually execute the move. The length of the used portion of tape S determines the time it takes to scan it, so we need to find an upper bound on this length. To do this, we can sum the lengths of the active portions of all k tapes in machine M . Each of these used portions has length at most t ( n ), since if at each step the head moves right, then M uses t ( n ) tape cells in t ( n ) steps; and if the head ever moves left, then M uses even fewer cells. Thus, scanning the active portion of tape S takes O ( t ( n )) steps.

为了模拟机器M的每个步骤,S执行两个完整的转换,并且可能最多对内容进行k 次右移。其中每一项都需要时间O ( t ( n )),因此机器S模拟一个步骤M 的总时间为O ( t ( n ))。

To simulate each step of machine M , S performs two full passes and potentially up to k right shifts of content. Each of these takes time O ( t ( n )), so the total time for machine S to simulate one step of M is O ( t ( n )).

我们现在可以估计模拟所需的总时间。S将其磁带调整为适当形式的预备步骤需要O ( n ) 个步骤。随后,S模拟机器M的每t ( n ) 个步骤,每个步骤使用O ( t ( n )) 个步骤,因此这部分模拟需要t ( n ) × O ( t ( n )) = O ( t 2 ( n )) 步骤。因此,机器M整个模拟需要O ( n )+ O ( t2 ( n ))步。

We can now estimate the total time required by the simulation. The initial step, in which S gets its tape into shape, requires O ( n ) steps. Then S simulates each of the t ( n ) steps of machine M using O ( t ( n )) steps, so this part of the simulation requires t ( n ) × O ( t ( n )) = O ( t 2 ( n )) steps. Thus the entire simulation of machine M requires O ( n ) + O ( t 2 ( n )) steps.

我们假设t ( n ) ≥ n(这是一个合理的假设,因为M甚至无法在更短的时间内读取整个输入单词)。由此可见S的运行时间为O ( t2 ( n )),这就完成了证明。

We have assumed that t ( n ) ≥ n (this is a reasonable assumption, since M could not even read the entire input word in less time). This implies that the running time of S is O ( t 2 ( n )), which completes the proof.

现在考虑非确定性单带图灵机的类似定理。我们将证明,任何可由此类机器判定的语言也可由确定性单带图灵机判定,这需要更多的时间。在此之前,我们需要定义非确定性图灵机的运行时。回想一下,如果非确定性图灵机对于所有输入字在所有计算路径上停止(完成计算),那么它就是一个决胜局机器。

Now consider the analogous theorem for nondeterministic single-tape Turing machines. We will show that any language that is decidable by such a machine is also decidable by a deterministic single-tape Turing machine, which requires significantly more time. Before we do that, we need to define the running time for a nondeterministic Turing machine. Recall that a nondeterministic Turing machine is a decidable machine if it halts (terminates) on all paths of computation, for all input words.

定义 7.9

Definition 7.9

N为决定某种语言的非确定性图灵机。运行时间 N是f : N N的函数,其中f ( n ) 是N在任何长度为n的输入字的任何计算路径上执行的最大步数,如下图所示。

Let N be a nondeterministic Turing machine deciding about some language. The running time of N is a function f : N N , where f ( n ) is the maximum number of steps taken by N on any path of computation for any input word of length n , as shown in the figure below.

7.10

确定性和非确定性机器的计时

Figure 7.10

Measuring the time of a deterministic and nondeterministic machine

非确定性图灵机运行时的定义并不旨在反映任何现实的计算机。正如我们很快就会看到的,这只是一个有用的数学定义,可以帮助分析一类重要计算问题的复杂性。

The definition of the running time of a nondeterministic Turing machine is not intended to represent any realistic computing machine. It is merely a useful mathematical definition that helps in analyzing the complexity of an important class of computational problems, as we will see shortly.

定理7.11

Theorem 7.11

t ( n ) 为满足t ( n ) ≥ n的函数。那么对于每个在时间t ( n ) 运行的非确定性图灵机,都有一个运行时间为 2O ( t ( n ))的单带确定性图灵机。

Let t ( n ) be a function such that t ( n ) ≥ n . Then for every nondeterministic Turing machine running in time t ( n ), there exists a single-tape deterministic Turing machine of running time 2O ( t ( n )) .

证明 N为在时间t ( n )运行的非确定性图灵机模拟N的确定性图灵机D,即搜索机器N的非确定性计算树。现在我们将分析这个模拟。

Proof Let N be a nondeterministic Turing machine running in time t ( n ). We construct a deterministic Turing machine D simulating N using the method shown in the proof of Theorem 3.16, which consists in searching the nondeterministic computation tree of N . We now analyze this simulation.

对于长度为n的输入字,计算树N中的每个非确定性路径的长度至多为t ( n )。树的每个顶点最多有b个子节点,其中b是由转换函数N产生的最大选择数。这意味着树上的叶子总数最多bt ( n )

For an input word of length n, every nondeterministic path in the computation tree N has length at most t ( n ). Each vertex of the tree has at most b children, where b is the maximum number of choices resulting from the transition function of N. This means that the total number of leaves in the tree is at most b t ( n ) .

模拟通过遍历树来进行。换句话说,我们先访问深度d处的所有顶点,然后再访问深度d + 1 处的任何顶点。定理 3.16 的证明中给出的算法效率低下,每次访问该顶点时都会从根向下继续到该顶点。然而,消除这种低效率并不会影响所讨论的定理,因此我们保持算法不变。树中的节点总数小于最大叶子数的两倍,因此我们可以将其限制为O ( b t ( n ) )。从根向下到达当前顶点所需的时间为O ( t ( n ))。因此D 的运行时间为O ( t ( n ) b t ( n ) ) = 2 O ( t ( n ))

The simulation proceeds by breadth-first traversal of the tree. In other words, we visit all vertices at depth d before going to any vertex at depth d + 1. The algorithm given in the proof of Theorem 3.16 is inefficient and proceeds from the root down to a vertex each time it visits that vertex. However, eliminating this inefficiency does not affect the theorem under consideration, so we leave the algorithm unchanged. The total number of vertices in the tree is less than twice the maximum number of leaves, so we can bound it by O ( b t ( n ) ). The time it takes to traverse from the root down to the current vertex is O ( t ( n )). Hence, the running time of D is O ( t ( n ) b t ( n ) ) = 2 O( t ( n )) .

正如定理 3.16 的证明中所述,机器D有三盘磁带。根据定理 7.8,将其转换为单带图灵机至多是运行时间的平方。因此,单带模拟器的运行时间为 (2 O( t ( n )) ) 2 = 2 O(2 t ( n )) = 2 O( t ( n )),从而完成证明。

As described in the proof of Theorem 3.16, the machine D has three tapes. By Theorem 7.8, transforming it into a single-tape Turing machine squares the running time at most. Hence, the running time of the single-tape simulator is (2 O( t ( n )) ) 2 = 2 O(2 t ( n )) = 2 O( t ( n )) , which completes the proof.

7.2

P级

7.2

Class P

定理 7.8 和 7.11 说明了一个重要的区别。一方面,我们展示了在确定性单磁带机和多磁带机上解决的问题的时间复杂度之间的二次或多项式关系。另一方面,我们已经证明,当我们测量确定性和非确定性图灵机问题的时间复杂度时,结果可能呈指数变化。

Theorems 7.8 and 7.11 illustrate an important distinction. On the one hand, we have shown a quadratic, or polynomial , relation between the time complexities of problems solvable on deterministic single- and multitape machines. On the other hand, we have shown that when we measure the time complexity of problems for deterministic and nondeterministic Turing machines, the results can differ exponentially .

多项式时间

Polynomial time

从我们的需求的角度来看,我们会将运行时间的多项式差异视为较小,而将指数差异视为较大。让我们考虑一下为什么我们决定在多项式和指数函数之间进行除法,而不是在其他一些函数类别上进行除法。

For our purposes, we will treat polynomial differences in running times as small, while exponential differences as large. Let's consider why we decided to divide between polynomials and exponential functions, and not for some other classes of functions.

首先,您可以注意到典型多项式函数(例如n 3 )和典型指数函数(例如 2 n )的增长率之间存在很大差异。我们以n = 1000为例,这是算法的合理输入字长。在这种情况下,n 3是 10 亿——一个很大的数字,但在我们的能力范围内。然而,2n一个比宇宙中原子数量大得多的数字。多项式时间算法对于许多应用来说通常足够快,而指数时间算法很少有用。

First, you can see the big difference in the growth rate of typical polynomial functions, such as n 3 , and typical exponential functions, such as 2 n . For example, consider n = 1000, which is a reasonable input word size for an algorithm. In this case, n 3 is 1 billion—a large number, but within our reach. And 2 n is a number much larger than the number of atoms in the universe. Polynomial-time algorithms are usually fast enough for many applications, whereas exponential-time algorithms are rarely useful.

指数时间算法通常出现在我们试图通过搜索整个可能解决方案空间来解决问题的情况下,有时称为暴力搜索”。例如,将数字分解为质因数的一种方法是检查所有潜在的约数。解空间的大小与数字的大小成指数关系,因此遍历它需要指数时间。有时,您可以通过更多地了解问题来避免强力搜索,这可能会产生更有用的多项式算法。

Exponential-time algorithms usually appear in situations where we try to solve a problem by searching the entire space of possible solutions, which is sometimes called brute -force search . For example, one way to factor a number is to examine all potential divisors. The size of the solution space is exponential in the size of the number, so it takes exponential time to scan it. Sometimes, brute-force search can be avoided by understanding the problem in more detail, which may lead to a more useful polynomial-time algorithm.

所有合理的确定性计算模型都是多项式等价的。这意味着它们每个人最多可以在多项式时间内相互模拟。通过说所有合理的确定性模型都是多项式等价的,我们并不是试图定义“合理”一词的含义。尽管如此,我们的意思是这个术语足够广泛,包括可以很好地近似真实计算机运行时间的模型。例如,定理 7.8 表明确定性单带图灵机和多带图灵机是多项式等价的。

All reasonable deterministic models of computation are polynomially equivalent . That is, each of them can simulate every other in at most polynomially greater time. In saying that all reasonable deterministic models are polynomially equivalent, we are not trying to define what is meant by reasonable . Nevertheless, we mean the notion to be broad enough to include models that closely approximate the running time of real computers. For example, Theorem 7.8 shows that deterministic single- and multitape Turing machines are polynomially equivalent.

从现在开始,我们将只处理复杂性理论中与运行时间多项式差异无关的部分。忽略这些差异将使我们能够建立一个不依赖于特定计算模型的选择的理论。回想一下,我们的目标是呈现计算的基本属性,而不是图灵机或任何其他选定模型的属性。

From this point on, we will only be concerned with those parts of complexity theory for which polynomial differences in running times are irrelevant. Ignoring these differences will allow us to construct a theory that is independent of the choice of a particular model of computation. Recall that our goal is to present the fundamental properties of computation , not the properties of Turing machines or any other chosen model.

人们可能认为忽略运行时的多项式差异是荒谬的。真正的程序员当然会注意到这样的差异,并努力确保程序的速度至少提高一倍。然而,我们已经通过引入渐近符号忽略了常数因子。我们现在建议忽略更大的多项式差异,例如时间n和时间n 3之间的差异。

One might think that neglecting polynomial differences in running times is absurd. Real programmers certainly pay attention to such differences and work hard to ensure that the program runs at least twice as fast. Nevertheless, we have neglected constant factors before, when we introduced asymptotic notation. Now we propose to neglect much larger polynomial differences, such as between time n and time n 3 .

忽略多项式差异的决定并不意味着我们认为此类差异不重要。相反,我们绝对认为时间n和时间n 3之间的差异很重要。然而,有些问题,例如因式分解问题是多项式问题还是非多项式问题,不依赖于多项式差异,并且也非常相关。我们只是决定关注这些类型的问题。只见树木不见森林并不意味着一个比另一个更重要——只是选择了不同的视角。

The decision to ignore polynomial differences does not mean that we consider such differences unimportant. On the contrary, we definitely consider the difference between time n and time n 3 to be important. However, some questions, such as whether a factoring problem is polynomial or nonpolynomial, do not depend on polynomial differences and are also very important. We simply decided to focus on questions of this type. Ignoring the trees in order to see the forest does not mean that some are more important than others—it is merely choosing a different perspective.

现在我们继续讨论对于复杂性理论非常重要的定义。

We now turn to a definition very important for complexity theory.

定义7.12

Definition 7.12

P是一类在确定性单带图灵机上可在多项式时间内判定的语言。换句话说,

P is the class of languages ​​that are decidable in polynomial time on a deterministic single-tape Turing machine. In other words,

P 类在我们的理论中起着核心作用,其重要性源于以下属性:

The class P plays a central role in our theory, and its importance stems from the following properties:

  1. P 的定义与计算模型的选择无关,只要它在多项式上等价于确定性单带图灵机即可。
  2. The definition of P is independent of the choice of model of computation, as long as it is polynomially equivalent to a deterministic single-tape Turing machine.
  3. P 类大致对应于计算机实际可以解决的问题类别。
  4. The class P roughly corresponds to the class of problems that can actually be solved on computers.

第 1 点表明,从数学角度来看,P 类是一个稳健的类。它不受我们使用的计算模型的具体属性的影响。

Point 1 indicates that class P is a robust class from a mathematical point of view. It is not affected by the specific properties of the computational model we use.

第2点意味着P级从实用角度来看很重要。如果问题属于 P,则有一种方法可以解决它,该方法将在某个常数k的时间nk中运行。这个运行时是否真正实用取决于k和应用程序。当然, n 100的运行时间在实践中通常没有用处。然而,采用多项式时间作为问题实际可解性的阈值被证明是有用的。当我们为以前似乎需要指数时间的问题找到多项式时间算法时,我们已经获得了一些关键见解,并且通常可以进一步降低时间复杂度,通常可以达到解决方案在以下情况下可行的程度:实践。

Point 2 means that the class P is of practical importance. If the problem belongs to P, then there is a method for solving it that will run in time n k for some constant k . Whether this running time is really practical depends on k and on the application. Of course, a running time of n 100 will not generally be useful in practice. Nevertheless, it is useful to take polynomial time as the threshold for practical solvability. When we find a polynomial-time algorithm for a problem that previously seemed to require exponential time, we gain some key insights and can usually reduce the time complexity even further, often to the point where the solution turns out to be practical.

P 类问题的示例

Examples of P class problems

在提出多项式时间算法时,我们只会提供高级描述,而不会提及特定计算模型的特征。这样我们就可以避免有关磁带和头部运动的无聊细节。然而,我们将坚持特定的算法描述约定,以便我们可以根据多项式运行时间来分析它们。

When presenting polynomial-time algorithms, we will provide only a high-level description, without referring to any specific features of the computational model. In this way, we avoid the tedious details of tapes and head movements. However, we will stick to certain conventions for describing algorithms so that they can be analyzed in terms of polynomial-time.

我们将继续用编号步骤描述算法。但是,我们必须注意图灵机实现算法每一步所执行的操作数量,以及算法所使用的总步骤数。

We will still describe algorithms in terms of numbered steps. However, we need to pay attention to the number of operations performed by the Turing machine to complete each step of the algorithm, as well as the total number of steps used by the algorithm.

当分析一个算法以证明它在多项式时间内运行时,我们需要做两件事。首先,我们需要提供算法在计算长度n的输入字时所采取的步数的多项式上限(通常使用大 O 表示法)。其次,我们需要检查算法描述中的各个步骤,以确保每个步骤都可以在合理的确定性计算模型上以多项式时间实现。在描述算法时,我们将其分为步骤,以便于分析的第二部分。完成这两项任务后,我们可以得出结论,该算法在多项式时间内工作,因为我们已经证明它适用于多项式数量的步骤,每个步骤都可以在多项式时间内执行,并且多项式的组合是多项式的。

When analyzing an algorithm to show that it runs in polynomial time, we need to do two things. First, we need to give a polynomial upper bound (usually using big O notation) on the number of steps the algorithm takes when computing an input word of length n . Second, we need to examine the individual steps in the algorithm description to make sure that each can be implemented in polynomial time on a reasonable deterministic model of computation. When describing an algorithm, we divide it into steps in such a way that the second part of the analysis is easier. Once we have done both of these things, we can conclude that the algorithm runs in polynomial time, since we have shown that it runs for a polynomial number of steps, each of which can be performed in polynomial time, and the composition of polynomials is polynomial.

还需要注意的是问题的表现方式。我们将继续使用尖括号符号< · >来表示一个或多个对象作为单词的合理编码,但不指定这种编码的具体方法。这次,一种合理的方法是允许多项式时间将对象编码和解码为其自然形式或其他合理表示。所有众所周知的表示图、自动机和其他类似对象的方法都是合理的。然而,应该注意的是,编码数字的一元表示法(其中数字 17 被写为一元序列 11111111111111111)是不合理的,因为它比真正合理的表示法指数大,例如任何k的基k表示法≥2。

What still needs attention is how the problems are represented. We will continue to use the angle bracket notation 〉 to denote a reasonable encoding of one or more objects as a word, but without specifying a specific method for doing so. This time, a reasonable method is one that allows polynomial time for encoding and decoding the objects into their natural form or some other reasonable representation. All the well-known ways of representing graphs, automata, and other such objects are reasonable. However, it should be noted that the unary notation for encoding numbers (in which the number 17 is written as the unary sequence 11111111111111111) is not reasonable, since it is exponentially larger than truly reasonable notations, such as the base- k notation for any k ≥ 2.

本章中我们将遇到的许多计算问题都涉及图表示。对图进行编码的一种合理方法是列出其顶点和边。另一种方式是邻接矩阵,其中当从顶点i到顶点j存在边时,元素 ( i , j ) 等于 1 ,或者当没有边时元素 ( i , j ) 等于 0 。在图算法的分析中,运行时间可以用顶点的数量来表示,而不是图表示的大小。在合理的图表示中,表示的大小是关于顶点数量的多项式。因此,如果我们分析一个算法并表明其运行时间相对于顶点数量是多项式(或指数)的,我们就知道它相对于输入字的大小也是多项式(或指数)的。

Many of the computational problems we will encounter in this chapter involve graph representations. One reasonable way to encode a graph is as a list of its vertices and edges. Another way is as an adjacency matrix , where element ( i , j ) is equal to 1 if there is an edge from vertex i to vertex j , and 0 if there is none. In the analysis of graph algorithms, the running time can be expressed in terms of the number of vertices, not the size of the representation of the graph. In reasonable graph representations, the size of the representation is polynomial in the number of vertices. Thus, if we analyze an algorithm and show that its running time is polynomial (or exponential) in the number of vertices, we know that it is also polynomial (or exponential) in the size of the input word.

第一个问题涉及有向图。有向图G包含顶点st,如下图所示。PATH问题是确定是否存在从st的路径。让

The first problem presented concerns directed graphs. A directed graph G contains vertices s and t , as shown in the figure below. The PATH problem is to determine whether there is a directed path from s to t . Let

PATH = { G , s , t G是一个有向图,包含从st 的有向路径}。

PATH = { G , s , t : G is a directed graph that contains a directed path from s to t }.

7.13路径 问题:是否存在从st

的路径?

Figure 7.13

The PATH problem: Is there a path from s to t ?

定理7.14

Theorem 7.14

路径 P

PATH P.

证明的概念我们通过提出解决PATH 的 多项式时间算法来证明这个定理。在描述该算法之前,我们可以注意到暴力算法不够快。

Concept of Proof We prove this theorem by presenting a polynomial-time algorithm to decide PATH . Before describing this algorithm, we may note that the brute-force algorithm is not fast enough.

PATH问题的强力算法是检查G中存在的所有潜在路径,并确定其中是否有一条是从st 的有向路径。潜在路径是属于G的顶点序列,长度最多为m,其中m是G的顶点数。(如果存在从st的有向路径,则还必须存在一条长度至多为m的路径,因为重复顶点是不必要的。)但是,此类潜在路径的数量为mm量级,即也就是说,它相对于G 的顶点数量呈指数关系。因此,暴力算法需要指数时间。

The brute force algorithm for the PATH problem consists of examining all potential paths that exist in G and determining whether any of them is a directed path from s to t . A potential path is a sequence of vertices in G of length at most m , where m is the number of vertices in G . (If there is a directed path from s to t , then there must also be one of length at most m , since repeating a vertex is never necessary.) However, the number of such potential paths is of the order of m m , which is exponential in the number of vertices in G . Thus, the brute force algorithm requires exponential time.

为了获得PATH问题的多项式算法,我们需要做一些事情来避免暴力搜索。一种方法是使用图搜索方法,例如广度优先搜索。通过这种方式,我们可以顺序标记图G的所有顶点,这些顶点可以通过长度为 1、然后是 2、3 等、直到m的有向路径从顶点s到达。很容易看出我们的策略在多项式时间内有效。

To obtain a polynomial-time algorithm for the PATH problem , we need to do something to avoid brute-force search. One way to do this is to use a graph search method such as breadth-first search. In this way, we can successively label all vertices of the graph G that are reachable from vertex s by directed paths of length 1, then 2, 3, and so on, up to m . It is easy to see that our strategy runs in polynomial time.

证明PATH问题的 多项式M算法的工作原理如下。

Proof The polynomial algorithm M for the PATH problem works as follows.

M = "对于输入词G , s , t ,其中G是包含顶点st的有向图:

M = "For an input word G , s , t , where G is a directed graph containing vertices s and t :

  1. 用 s标记顶点。
  2. Label the vertex s .
  3. 重复下一步,直到选择新的顶点。
  4. Repeat the next step until new vertices are selected.
  5. 浏览所有G边。如果其中存在从标记顶点a到未标记顶点b的边 ( a , b ) ,则标记顶点b
  6. Traverse all edges of G . If there is an edge ( a , b ) from labeled vertex a to unlabeled vertex b , label vertex b .
  7. 如果t被标记,则接受。否则,丢弃。”
  8. If t is tagged, accept . Otherwise reject ”.

我们现在将分析该算法以表明它在多项式时间内运行。很明显,步骤 1 和 4 只执行一次。步骤3最多执行m次,因为每次都会标记图G的另一个顶点。因此,执行的总步数最多为 1 + 1 + m 这是关于图G的大小的多项式。

We now analyze this algorithm to show that it runs in polynomial time. It is clear that steps 1 and 4 are executed only once. Step 3 is executed at most m times, since each time a new vertex of G is labeled . Thus, the total number of steps executed is at most 1 + 1 + m , which is polynomial in the size of G .

M算法的步骤 1 和 4可以在任何合理的确定性模型中在多项式时间内轻松实现。步骤 3 涉及遍历整个输入单词并检查特定顶点是否被标记,这也可以在多项式时间内轻松完成。由此可见,M是PATH问题的多项式时间算法。

Steps 1 and 4 of M can be easily implemented in polynomial time in any reasonable deterministic model. Step 3 involves traversing the entire input word and checking whether certain vertices are labeled, which can also be easily implemented in polynomial time. It follows that M is a polynomial-time algorithm for the PATH problem .

现在让我们考虑多项式时间算法的另一个例子。如果除两个数的最大数是 1 ,我们就说它们是互质的。例如,10 和 21 是互质的,尽管它们都不是质数,而 10 和 22 不是互质的,因为它们都可以被 2 整除。让RELPRIME成为问题检查两个数是否互质。换句话说

Now let's consider another example of a polynomial-time algorithm. We say that two numbers are relatively prime if the largest number that divides both of them is 1. For example, 10 and 21 are relatively prime, although neither is prime, whereas 10 and 22 are not relatively prime because both are divisible by 2. Let RELPRIME be the problem of testing whether two numbers are relatively prime. In other words,

RELPRIME = { x , y : xy互质 }。

RELPRIME = { x , y : x and y are relatively prime }.

定理7.15

Theorem 7.15

RELPRIME ® P

RELPRIME P.

证明的概念 解决这个问题的算法可以简单地检查两个数字的所有潜在约数,如果没有找到任何大于 1 的数字可以整除这两个数字,则接受。然而,以二进制或任何其他基数k ≥ 2表示的数字的值相对于其表示的长度呈指数关系。因此,这样的强力算法必须检查指数级的许多潜在除数,因此它将具有指数级的运行时间。

Proof Concept An algorithm to solve this problem can simply check all potential divisors of both numbers and accept if it finds no greater than 1 that divides both numbers. However, the value of a number written in binary representation or any other notation in base k ≥ 2 is exponential in the length of its representation. Thus, such a brute-force algorithm must check exponentially many potential divisors and will therefore have exponential running time.

相反,我们将使用一种古老的数值程序来解决这个问题,这种程序被称为欧几里得算法,用于寻找最大公约数。自然数xy的最大公约数,写作 GCD( x , y ) ,是整除xy且没有余数的最大整数。例如,GCD(18, 24) = 6。显然,当且仅当 GCD( x , y ) = 1 时, xy互质。在给出的证明中,我们将欧几里得算法描述为算法E。它使用 mod 函数,其工作方式是x mod y是x除以y的余数。

Instead, we will solve this problem by using an ancient numerical procedure for finding the greatest common divisor, called the Euclidean algorithm . The greatest common divisor of natural numbers x and y , written as GCD( x , y ), is the largest integer that divides x and y without a remainder . For example, GCD(18, 24) = 6. It is clear that x and y are relatively prime if and only if GCD( x , y ) = 1. In the proof that follows, we will describe the Euclidean algorithm as the algorithm E . It uses the function mod , which operates so that x mod y is the remainder of dividing x by y .

证明 欧几里得算法E的工作原理如下。

Proof The Euclidean algorithm E works as follows.

E = "对于输入词x , y ,其中xy是二进制表示的自然数:

E = "For input word x , y , where x and y are natural numbers in binary notation:

  1. 重复直到y = 0:
  2. Repeat until y = 0:
  3. 指定xx mod y
  4. Assign xx mod y .
  5. 交换xy
  6. Swap x and y .
  7. 返回x ”。
  8. Return x ".

R算法通过使用E算法作为子程序来解决RELPRIME问题。

Algorithm R solves the RELPRIME problem using algorithm E as a subroutine.

R = "对于输入词x , y ,其中xy是二进制表示的自然数:

R = "For input word x , y , where x and y are natural numbers in binary notation:

  1. x , y 运行E
  2. Run E for x , y .
  3. 如果结果为 1,则接受。否则,丢弃。”
  4. If the result is 1, accept . Otherwise, reject ."

显然,如果E有效且在多项式时间内运行,则R也有效且在多项式时间内运行,因此我们只需要分析算法E。它的正确性是众所周知的,所以我们在这里不再讨论它。

It is clear that if E is correct and runs in polynomial time, then R is also correct and runs in polynomial time, so we only need to analyze the algorithm E . Its correctness is perfectly well known, so we will not concern ourselves with it here.

为了研究算法E的时间复杂度,我们首先将证明步骤 2 的每次执行(可能除了第一次)都会将x的值至少除以一半。执行步骤 2 后,由于 mod 函数的特性,我们得到x < y 。在第 3 步之后,我们有x > y,因为这些值已被交换。因此,当我们稍后执行步骤 2 时,我们有 x > y。如果x /2 ≥ y,则x mod y < yx /2 并且x的值至少减少一半。如果x /2 < y,则x mod y = xy < x /2 ,并且x的值再次减少至少一半。

To investigate the time complexity of algorithm E , we first show that each execution of step 2 (except perhaps the first) divides the value of x by at least half. After step 2, we have x < y , because of the properties of the mod function. After step 3, we have x > y , because these values ​​have been swapped. So on a later execution of step 2, we have x > y . If x /2 ≥ y , then x mod y < yx /2 and the value of x is reduced by at least half. If x /2 < y , then x mod y = xy < x /2 and again the value of x is reduced by at least half.

每次执行步骤3时都会交换xy值,因此每次循环运行时原始xy值都会至少减少一半。由此可见,步骤2和步骤3的最大执行次数为2 log 2 x和2 log 2 y中较小的一个。这些对数与数字表示的长度成正比,给出这些步骤的执行次数约为O ( n )。E算法的每一步都是在多项式时间内执行的,因此总的执行时间也是多项式的。

The values ​​x and y are swapped on each execution of step 3, so each of the original values ​​x and y is reduced by at least half on each iteration of the loop. This implies that the maximum number of executions of steps 2 and 3 is the lesser of 2 log 2 x and 2 log 2 y . These logarithms are proportional to the lengths of the representation of the numbers, giving a number of executions of these steps of order O ( n ). Each step of E executes in polynomial time, so the total execution time is also polynomial.

多项式时间算法的最后一个例子表明,每种上下文无关语言都可以在多项式时间内判定。

The last example of a polynomial-time algorithm shows that every context-free language is decidable in polynomial time.

定理7.16

Theorem 7.16

每个上下文无关语言都属于 P 类。

Every context-free language belongs to the class P.

证明的概念 在定理 4.9 中,我们证明了每种上下文无关语言都是可判定的。为此,我们提供了一种算法来解决任何给定的 CFL。如果该算法在多项式时间内运行,那么我们当前的定理就是该结果的结论。那么让我们回忆一下这个算法并检查它是否运行得足够快。

Concept of the Proof In Theorem 4.9 we proved that every context-free language is decidable. To this end we gave an algorithm that decides every given CFL. If this algorithm runs in polynomial time, then our current theorem is a corollary of that result. Let us recall this algorithm and check whether it runs sufficiently fast.

L是由乔姆斯基范式中的上下文无关文法G生成的上下文无关语言。在问题 2.26 中,我们表明,如果G是乔姆斯基范式,则单词w的每次推导都需要 2n−1 个步骤,其中n是w的长度。语言L的解析机的操作包括在 2n−1 个步骤中尝试对长度为n的给定单词进行所有可能的推导。如果这些引脚中的任何一个是中的引脚,则机器接受;否则它会拒绝。

Let L be a context-free language generated by a context-free grammar G in Chomsky normal form. In Problem 2.26 we showed that, provided G is in Chomsky normal form, then any derivation of a word w takes 2n−1 steps, where n is the length of w . The action of the deciding machine for a language L is to try, for a word of length n, all possible derivations in 2n−1 steps. If any of these derivations is a derivation of w , the machine accepts; otherwise it rejects.

对该算法的快速检查表明它不是在多项式时间内运行。k步推导的数量可能相对于k呈指数,因此该算法可能需要指数时间。

A quick analysis of this algorithm shows that it does not run in polynomial time. The number of derivations with k steps may be exponential in k , so this algorithm may require exponential time.

为了获得多项式时间算法,我们将介绍一种非常强大的技术,称为动态规划。该技术使用有关较小子问题的信息收集来解决较大的子问题。我们记录每个子问题的解决方案,以便我们只解决一次。我们将子问题的解决方案存储在表中,当算法找到解决方案时,我们将其输入到该表中。

To obtain a polynomial-time algorithm, we introduce a very powerful technique called dynamic programming . This technique uses the accumulation of information about smaller subproblems to solve larger subproblems. We record the solution to each subproblem so that we only have to solve it once. We store the solutions to the subproblems in an array, to which we enter solutions as the algorithm finds them.

在这种情况下,我们考虑确定属于G的给定变量是否生成属于w的某个子词的子问题。该算法将该子问题的解输入到一个n × n数组中。对于ij,该数组的元素 (i, j ) 包含生成子字w i w i +1 ... w j的变量集。对于i > j,不使用数组条目。

In this case we consider the subproblem of determining whether a given variable in G generates some subword in w . The algorithm stores the solution to this subproblem in an n × n array . For ij , the element (i, j ) of this array contains the set of variables that generate subword w and w i +1w j . For i > j , the array entries are not used.

该算法填充中每个子字的数组元素。它首先填充长度为 1 的子字条目,然后填充长度为 2 的子字条目,依此类推。在确定较大长度的条目时使用较小长度的条目。

The algorithm fills the array elements for each substring in . It first fills the entries for substrings of length 1, then those of length 2, and so on. It uses the entries for smaller lengths while determining the entries for larger lengths.

例如,假设算法已经确定哪些变量生成长度为k或更小的所有子字。为了确定变量A是否生成长度为k + 1的某个子字,算法以k种可能的方式将该字分割成两个非空片段。对于每个分割,算法使用之前从数组中计算的值检查每个产生式A BC以确定B是否生成第一部分而C是否生成第二部分。如果BC生成适当的部分,则A生成一个子字,并将该解决方案添加到表中的适当条目中。该算法从长度为 1 的字开始,在数组中搜索产生式A b

For example, suppose the algorithm has already determined which variables generate all subwords of length k or less . To determine whether a variable A generates a certain subword of length k + 1, the algorithm splits the word into two nonempty fragments in k possible ways. For each partition, the algorithm examines each production A BC to determine whether B generates the first part and C the second part, using previously computed values ​​from the array. If B and C generate corresponding parts, then A generates a subword and this solution is added to the appropriate entry in the array. The algorithm starts with words of length 1, searching the array for the production A b .

证明 所提出的算法D实现了证明概念中提出的想法。令G为乔姆斯基范式上下文无关语法,生成上下文无关语言L。S为初始变量。 (回想一下,在乔姆斯基的范式语法中,空词以特殊方式处理;该算法在步骤 1 中处理w = ε的情况。)我们已将注释放在双方括号中。

Proof The presented algorithm D implements the idea presented in the proof concept. Let G be a context-free grammar in Chomsky normal form that generates a context-free language L . Let S be an initial variable. (Recall that in a Chomsky normal form grammar, empty words are treated in a special way; the algorithm handles this case for w = ε, in Step 1.) We have enclosed comments in double square brackets.

D =“对于输入字w = w 1 ... w n

D = "For input word w = w 1 w n :

  1. 对于w = ε,如果存在产生式S ε,则接受;否则丢弃1情况w = ε1
  2. For w = ε, if there is a production S ε, accept ; otherwise reject . case w = ε
  3. 对于i = 1 到n1检查长度为 1 的每个子字1
  4. For i = 1 to n : examine each subword of length 1
  5. 对于每个变量A
  6. For each variable A :
  7. 检查是否存在产生式A b,其中b = w i
  8. Check whether there is a production A b , where b = w i .
  9. 如果是,则将A插入到 数组( i , i ) 中。
  10. If so, insert A into  array ( i , i ).
  11. 对于l = 2 到n1l是子字的长度1
  12. For l = 2 to n : l is the length of the subword
  13. 对于i = 1 到nl + 1:1i是子字的起始位置1
  14. For i = 1 to nl + 1: i is the starting position of the subword
  15. j = i + l − 1。j1子词的最终位置1
  16. Let j = i + l − 1. j is the final position of the subword
  17. 对于k = ij − 1:1k是分区位置1
  18. For k = i to j − 1: k is the partition position
  19. 对于每个产生式A BC
  20. For each production A BC :
  21. 如果数组( i , k ) 包含B并且数组( k + 1, j ) 包含C,则将A放入数组( i , j )中 。
  22. If array ( i , k ) contains B and array ( k + 1, j ) contains C , put A into  array ( i , j ).
  23. 如果S数组(1, n ) 中,则接受;否则丢弃。”
  24. If S is in array (1, n ), accept ; otherwise reject ".

我们来分析一下算法D。每个步骤都可以轻松实现以具有多项式执行时间。步骤4和5最多执行nv次,其中v是属于G的变量的数量,并且是与n无关的常数;因此这些步骤执行O ( n ) 次。

Let us analyze algorithm D . Each step can be easily implemented to have polynomial execution time. Steps 4 and 5 are executed at most nv times, where v is the number of variables belonging to G and is a constant independent of n ; thus, these steps are executed O ( n ) times.

步骤6最多执行n次。每次执行步骤6时,步骤7最多执行n次。每次执行步骤7时,步骤8和步骤9最多执行n次。每次执行步骤 9 时,步骤 10 都会执行r次,其中r是语法G中产生式的数量,从我们的角度来看是一个常数值。因此,算法最内层循环步骤11被执行O( n 3 )次。求和后,我们看到D需要O ( n 3 ) 步。

Step 6 is executed at most n times. Each time step 6 is executed, step 7 is executed at most n times. Each time step 7 is executed, steps 8 and 9 are executed at most n times. Each time step 9 is executed, step 10 is executed r times, where r is the number of productions in the grammar G and from our point of view is a constant value. Thus, step 11, the innermost loop of the algorithm, is executed O( n 3 ) times. By summing, we see that D executes O ( n 3 ) steps.

7.3

NP类

7.3

NP class

正如我们在 7.2 节中所示,对于许多问题,我们可以避免强力搜索并找到多项式解。然而,在一些特殊问题(包括许多有趣且有用的问题)中避免使用暴力方法的尝试尚未成功,并且还没有已知的多项式算法。

As we showed in Section 7.2, for many problems we can avoid brute-force search and find polynomial solutions. Nevertheless, attempts to avoid brute-force approaches in some special problems, including many interesting and useful ones, have not been successful, and no polynomial algorithms are known for them.

为什么我们不能找到解决这些问题的多项式算法?我们不知道这个重要问题的答案。也许这些问题可以通过基于未知原理的尚未发现的多项式时间算法来解决。也许其中一些问题根本无法在多项式时间内解决。他们的本质可能很困难。

Why can't we find polynomial-time algorithms for these problems? We don't know the answer to this important question. Perhaps these problems can be solved by as-yet-undiscovered polynomial-time algorithms based on as-yet-unknown principles. Perhaps some of these problems simply cannot be solved in polynomial time. They may simply be intractable by their very nature.

与这个问题相关的一项重要发现表明,许多问题的复杂性是相互关联的。针对此类问题的多项式时间算法可用于解决一整类问题。为了理解这种现象,让我们从一个例子开始。

One of the significant discoveries related to this question is that the complexities of many problems are related. A polynomial-time algorithm for one of these problems can be used to solve a whole class of problems. To understand this phenomenon, let's start with an example.

有向图G中的哈密顿量(或Hamiltonian ) 路径是仅经过每个顶点一次的路径。让我们考虑检查给定有向图是否包含连接两个选定顶点的哈密顿路径的问题,如下图所示。让

A Hamiltonian (or Hamiltonian ) path in a directed graph G is a path that passes through every vertex exactly once. Consider the problem of checking whether a given directed graph contains a Hamiltonian path connecting two given vertices, as in the figure below. Let

HAMPATH = { G , s , t G是一个有向图,包含从顶点st 的哈密顿路径}。

HAMPATH = { G , s , t : G is a directed graph containing a Hamiltonian path from vertex s to t }.

7.17

哈密顿路径通过每个顶点恰好一次

Figure 7.17

A Hamiltonian path passes through each vertex exactly once.

通过修改定理 7.14 中给出的 PATH 问题的强力算法,我们可以轻松获得HAMPATH问题的指数时间算法。我们只需要添加一个检查可能的路径是否是哈密顿量。没有人知道HAMPATH问题是否存在多项式时间解。

We can easily obtain an exponential-time algorithm for the HAMPATH problem by modifying the brute-force algorithm for the PATH problem given in Theorem 7.14. We only need to add a check that a possible path is Hamiltonian. Nobody knows whether there is a polynomial-time solution to the HAMPATH problem.

HAMPATH问题有一个称为多项式可验证性的属性,这对于理解其复杂性非常重要。即使我们不知道一种快速(多项式时间)方法来检查给定图是否包含哈密顿路径,如果我们找到这样的路径(可能使用指数时间算法),我们可以轻松地让其他人相信这样一条路是存在的,只是炫耀而已。换句话说,验证哈密顿路径的存在比确定它是否存在要容易得多。

The HAMPATH problem has a very important property for understanding its complexity called polynomial verifiability . Although we don't know a fast (i.e., polynomial-time) way to check whether a given graph contains a Hamiltonian path, if we find one (perhaps using an exponential-time algorithm), we can easily convince other people that such a path exists simply by showing it. In other words, verifying the existence of a Hamiltonian path is much easier than determining whether it exists at all.

另一个多项式可验证的问题是数字复杂度问题。回想一下,如果一个自然数是两个大于 1 的整数的乘积,那么它就是合数(换句话说,合数是非素数)。让

Another polynomially verifiable problem is the complexity of a number. Recall that a natural number is composite if it is the product of two integers greater than 1 (in other words, a composite number is one that is not a prime number). Let

COMPOSITES = { x : x = pq对于某些整数p , q > 1}。

COMPOSITES = { x : x = pq for some integers p , q > 1}.

我们可以轻松地检查一个数字是否是合数 - 只需找到该数字的除数即可。最近发现了一种检查给定数是否是素数或合数的多项式算法,但它比上面提到的复杂度验证方法要复杂得多。

We can easily check that a number is composite – all we have to do is find the divisor of that number. A polynomial algorithm has recently been discovered to check whether a given number is prime or composite, but it is much more complicated than the aforementioned method of verifying complexity.

有些问题可能无法在多项式时间内验证。作为一个例子,考虑HAMPATH问题,它是HAMPATH问题的补充。即使我们能够以某种方式(任意)确定给定的图不包含哈密顿路径,我们也知道其他人无法在不使用某种指数时间算法的情况下验证这种不存在。我们正式定义下面讨论的概念。

Some problems may not be verifiable in polynomial time. As an example, consider the HAMPATH problem , the complement of the HAMPATH problem . Even if we could somehow (arbitrarily) establish that a given graph does not contain a Hamiltonian path, we do not know of a way for someone else to verify this nonexistence without using some exponential-time algorithm. We define these concepts formally below.

定义 7.18

Definition 7.18

语言 A 的验证者是算法V,使得

The verifier for language A is such an algorithm V that

A = { w : V接受单词w , c 来表示某个单词c }。

A = { w : V accepts words w , c for some word c }.

我们将验证器的运行时间定义为字长w的函数,因此多项式验证器以相对于长度w 的多项式时间运行。如果语言A存在多项式验证器,则它是多项式可验证的。

We define the running time of a verifier as a function of the length of the word w , so a polynomial-time verifier runs in polynomial time with respect to the length w . A language A is polynomial-time verifiable if there exists a polynomial-time verifier for it.

验证者使用定义 7.18 中写为c 的附加信息来检查单词w是否属于A。我们将此信息称为属于语言A 的证书证明。我们可以注意到,对于多项式验证者,证书具有多项式长度(相对于字长w),因为这是验证者在多项式有限时间内可以读取的唯一长度。让我们将此定义应用到HAMPATHCOMPOSITES语言。

The verifier uses the additional information, written as c in Definition 7.18, to check whether the word w belongs to A . We call this information a certificate or proof of belonging to language A . We can see that for polynomial verifiers, the certificate has polynomial length (with respect to the length of the word w ), since this is the only length that the verifier can read in polynomial time. Let us apply this definition to the languages ​​HAMPATH and COMPOSITES .

在HAMPATH问题中,单词G , s , t HAMPATH的证明就是从顶点st 的哈密顿路径。对于复合问题,合数x的证书是它的约数之一。在这两种情况下,拥有可用证书的验证者可以在多项式时间内检查输入单词是否属于该语言。

In the case of the HAMPATH problem , the certificate for a word G , s , t HAMPATH is simply the Hamiltonian path from vertex s to t . For the COMPOSITES problem , the certificate for a composite number x is one of the divisors. In both cases, the verifier, given the certificate, can check in polynomial time that the input word belongs to the language.

定义 7.19

Definition 7.19

NP是存在多项式验证器的一类语言。

NP is a class of languages ​​for which polynomial verifiers exist.

NP 类很重要,因为它包含许多具有实际意义的问题。根据前面的考虑,HAMPATHCOMPOSITES都是 NP 类的成员。正如我们提到的,COMPOSITES也是 P 类的成员,P 类是 NP 类的子集,但证明这种更强的结果要困难得多。 NP 这个名称来自术语“非确定性多项式时间” 它来自使用非确定性多项式时间图灵机来定义此类的另一种方法。

The class NP is important because it contains many problems of practical importance. From the previous discussion, it follows that both HAMPATH and COMPOSITES are members of NP. As we mentioned, COMPOSITES is also a member of P, which is a subset of NP, but proving this stronger result is much more difficult. The name NP comes from the term "nondeterministic polynomial time" , which is derived from an alternative way of defining this class, which uses nondeterministic polynomial-time Turing machines.

下图所示是一个非确定性图灵机 (NTM),它在非确定性多项式时间内解决HAMPATH问题。回想一下,在定义 7.9 中,我们将非确定性机器的运行时间定义为完成最长计算路径所需的时间。

Below is a nondeterministic Turing machine (NTM) that solves the HAMPATH problem in nondeterministic polynomial time. Recall that in Definition 7.9 we defined the running time of a nondeterministic machine as the time it takes to execute the longest path of computations.

N 1 = "对于输入词G , s , t ,其中G是包含顶点st 的有向图:

N 1 = "For input G , s , t , where G is a directed graph containing vertices s and t :

  1. 编写m 个数字的列表,p 1 , …, p m,其中m是图G中的顶点数。列表中的每个数字都是从数字 1 到 m中不确定地选择的。
  2. Print out a list of m numbers, p 1 , …, p m , where m is the number of vertices in the graph G . Each number in the list is nondeterministically chosen from the numbers 1 to  m .
  3. 检查列表中是否有重复的内容。如果是这样,则丢弃.
  4. Check if there are any duplicates in the list. If so, discard .
  5. 检查s = p 1t = p m。如果不是,则丢弃
  6. Check if s = p 1 and t = p m . If not, reject .
  7. 对于从 1 到m − 1 的每个i,检查 ( pi , pi + 1 )是否是属于G的边。如果不是,则丢弃。否则,所有测试均成功,因此接受。”
  8. For each i from 1 to m − 1 , check whether ( p i , p i +1 ) is an edge in G . If not, reject . Otherwise, all tests are successful, so accept ”.

为了分析该算法并验证它在非确定性多项式时间内是否有效,我们将检查每个步骤。在步骤 1 中,非确定性选择显然是在多项式(或更精确地说是线性)时间内进行的。在步骤 2 和 3 中,每个部分都是一个简单的检查,因此它们一起以多项式时间运行。最后,步骤 4 也以多项式时间运行。因此,整个算法在非确定性多项式时间内运行。

To analyze this algorithm and verify that it runs in nondeterministic polynomial time, we examine each step of it. In step 1, the nondeterministic choice obviously runs in polynomial time (or, more precisely, linear time). In steps 2 and 3, each part is a simple check, so together they run in polynomial time. Finally, step 4 also runs in polynomial time. Thus, the entire algorithm runs in nondeterministic polynomial time.

定理7.20

Theorem 7.20

一种语言是 NP 类当且仅当它由在多项式时间内运行的某些非确定性图灵机判定时。

A language is in NP if and only if it is decided by some nondeterministic Turing machine running in polynomial time.

证明的概念 我们将展示如何将多项式验证器转换为具有多项式运行时间的等效非确定性图灵机,反之亦然。非确定性图灵机猜测证书并模拟验证者。验证者通过使用其接受计算路径作为证书来模拟NTM。

Proof Concept We show how to transform a polynomial-time verifier into its equivalent nondeterministic polynomial-time Turing machine, and vice versa. The nondeterministic Turing machine guesses the certificate and simulates the verifier. The verifier simulates the NTM by using its accepting computation path as the certificate.

证明 为了证明第一个定理,我们假设A NP 并想证明A是由非确定性多项式时间图灵机N求解的。令V为语言A的多项式验证器,其存在源于类 NP 的定义。我们假设V是在时间n k运行的图灵机,并将N构造为机器:

Proof To prove the first side of the theorem, we assume that A NP and we want to show that A is decidable by a nondeterministicpolynomial-time Turing machine N. Let V be a polynomial-time verifier of the language A , whose existence follows from the definition of the class NP. We assume that V is a Turing machine that runs in time n k and construct N as the machine:

N = “对于长度为n 的输入字w

N = "For input word w of length n :

  1. 不确定地选择长度最多为n k的单词c
  2. Nondeterministically choose a word c of length at most n k .
  3. 对输入词w , c 运行V
  4. Run V for input word w , c .
  5. 如果V接受,则接受;否则丢弃。”
  6. If V accepts, accept ; otherwise reject ."

为了反方向证明该定理,我们假设语言A由非确定性图灵机N在多项式时间内求解,并构造如下多项式V。

To prove the theorem in the opposite direction, we assume that the language A is decided in polynomial time by a nondeterministic Turing machine N and construct a polynomial-time V as follows.

V = "对于输入单词w , c ,其中w和 c是单词:

V = "For input word w , c , where w and  c are words:

  1. 针对输入单词w模拟机器N ,将单词c中的每个符号视为后续步骤中做出的不确定性选择的描述(类似于定理 3.16 的证明)。
  2. Simulate the machine N for input word w , treating each symbol in word c as a description of the nondeterministic choice made in subsequent steps (similar to the proof of Theorem 3.16).
  3. 如果机器N的这条计算路径是接受,则接受;否则丢弃。”
  4. If this computation path of machine N is accepting, accept ; otherwise reject ".

我们定义非确定性时间复杂度类 NTIME( t ( n )) 类似于确定性时间复杂度类 TIME( t ( n ))。

The nondeterministic time complexity class NTIME( t ( n )) is defined analogously to the deterministic time complexity class TIME( t ( n )).

定义 7.21

Definition 7.21

NTIME( t ( n )) = { L : L是由运行时间 O( t ( n ))的非确定性图灵机解析的语言}。

NTIME( t ( n )) = { L : L is a language decided by a nondeterministic Turing machine running in time O( t ( n ))}.

应用 7.22

Motion 7.22

NP = k NTIME( n k )。

NP = k NTIME( n k ).

NP 类不依赖于为非确定性计算选择合理模型,因为所有此类模型都是多项式等价的。在描述和分析非确定性多项式时间算法时,我们将遵循先前用于确定性多项式时间算法的约定。非确定性多项式时间算法的每一步都必须在合理的非确定性计算模型中具有明显的非确定性多项式时间实现。作为算法分析的一部分,我们需要证明每个计算路径最多使用多项式步数。

The class NP does not depend on the choice of a reasonable model of nondeterministic computation, since all such models are polynomial-time equivalent. In describing and analyzing nondeterministic polynomial-time algorithms, we will follow the conventions used earlier for deterministic polynomial-time algorithms. Each step of a nondeterministic polynomial-time algorithm must have an obvious implementation in nondeterministic polynomial time in reasonable nondeterministic computational models. As part of the analysis of the algorithm, we need to show that each path of computation uses at most a polynomial number of steps.

NP 类问题的示例

Examples of NP problems

无向图中的团是每两个顶点通过边连接的子图。我们使用术语k-clique来表示包含k 个顶点的团。图 7.23 展示了一个 5 派图。

A clique in an undirected graph is a subgraph whose every two vertices are connected by an edge. We use the term k-clique for a clique containing k vertices. Figure 7.23 illustrates a graph containing a 5-clique.

7.23

5 派图

Figure 7.23

A graph containing a 5-clique

团问题是确定图是否包含给定大小的团。让

The clique problem is to determine whether a graph contains a clique of a given size. Let

CLIQUE = { < G , k >G是包含k -clique的无向图}。

CLIQUE = { G , k : G is an undirected graph containing k -clique}.

定理7.24

Theorem 7.24

CLIQUE问题属于NP类。

The CLIQUE problem belongs to the class NP.

证明的概念 点击一下就是一个证书。

The concept of proof Click is a certificate.

下面的证明 CLIQUE问题的V验证器。

Proof Below is a verifier V for the CLIQUE problem .

V = "对于输入词〈〈G , k , c :

V = "For input word 〈〈G , k , c :

  1. 检查c是否是G的具有k 个顶点的子图。
  2. Check whether c is a subgraph of G with k vertices.
  3. 检查G是否包含连接属于c 的顶点的所有边。
  4. Check if G contains all edges connecting vertices belonging to c .
  5. 如果两项测试均成功,则接受;否则丢弃。”
  6. If both tests are successful, accept ; otherwise, reject ."

替代证明 如果人们更喜欢通过多项式非确定性图灵机的棱镜来查看 NP 类,则可以通过提供适当的CLIQUE语言解析器来证明该定理。人们可以注意到这两项证据的相似之处。

Alternative Proof If one prefers to view the class NP in terms of polynomial-time nondeterministic Turing machines, one can prove this theorem by providing a suitable machine that resolves the language CLIQUE . One can notice the similarity of the two proofs.

N = "对于输入词G , k ,其中G是一个图:

N = "For input word G , k , where G is a graph:

  1. 非确定性地选择包含图G的k 个顶点的子集c 。
  2. Nondeterministically choose a subset c containing k vertices of the graph G .
  3. 检查G是否包含连接属于c 的顶点的所有边。
  4. Check if G contains all edges connecting vertices belonging to c .
  5. 如果是这样,请接受;否则丢弃。”
  6. If so, accept ; otherwise reject ."

接下来,我们考虑整数运算的SUBSET-SUM问题。我们有一组特定的数字x 1 , ..., x k和目标值t。我们想要确定我们的集合是否包含总和为t 的子集。所以

Next, we consider the SUBSET-SUM problem in integer arithmetic. We have a multiset of numbers x 1 , …, x k and a target value t . We want to determine whether our set contains a subset that sums to t . Therefore,

SUBSET-SUM = { S, t : S = { x 1 , …, x k } 对于某些子集 { y 1 , …, y l } { x 1 , …, x k } 我们有Σ y i = t }。

SUBSET-SUM = { S, t : S = { x 1 , …, x k } and for some subset { y 1 , …, y l } { x 1 , …, x k } we have Σ y i = t }.

例如, {4, 11, 16, 21, 27}, 25 SUBSET-SUM,因为 4 + 21 = 25。请注意 { x 1 , …, x k } 和 { y 1 , … , y l } 是多重集,因此允许元素重复。

For example , 〈 {4, 11, 16, 21, 27}, 25 SUBSET-SUM , since 4 + 21 = 25. Note that both { x 1 , …, x k } and { y 1 , …, y l } are multisets , so repeated elements are allowed.

定理7.25

Theorem 7.25

SUBSET-SUM问题属于 NP 类。

The SUBSET-SUM problem belongs to the class NP.

证明的概念 相关子集是证书。

The Concept of Proof The corresponding subset is a certificate.

证明下面的V机是SUBSET-SUM语言的验证器。

Proof The following machine V is a verifier for the SUBSET-SUM language .

V = "对于输入词〈〈 S, t , c :

V = "For input word 〈〈 S, t , c :

  1. 检查c是否是总和为t 的数字多重集。
  2. Check whether c is a multiset of numbers that sum to t .
  3. 检查S是否包含属于c的所有数字。
  4. Check if S contains all numbers belonging to c .
  5. 如果两项测试均成功,则接受;否则丢弃。”
  6. If both tests are successful, accept ; otherwise, reject ."

替代证明我们还可以通过提出一个在多项式时间内解析SUBSET-SUM 语言的非确定性图灵机来证明这个定理

Alternate proof We can also prove this theorem by showing a nondeterministic Turing machine that resolves the SUBSET-SUM language in polynomial time.

N = "对于输入词 S, t

N = "For input word S, t :

  1. 非确定性地选择由属于S 的数字组成的子集c 。
  2. Nondeterministically choose a subset c consisting of numbers belonging to S .
  3. 检查c中的数字加起来是否等于t
  4. Check if the numbers belonging to c sum to t .
  5. 如果两项测试均成功,则接受;否则丢弃。”
  6. If both tests are successful, accept ; otherwise, reject ."

请注意, CLIQUESUBSET-SUM集对 NP 类的归属并不明显。验证某些东西不存在似乎比验证某些东西存在更难。我们创建一个单独的复杂性类,称为 coNP,其中包含属于 NP 类的语言的补充语言。目前尚不清楚 coNP 是否与 NP 不同。

Note that the class NP of the sets CLIQUE and SUBSET-SUM is not obvious. Checking that something is not present seems harder to verify than that something exists . We create a separate complexity class, called coNP, which contains languages ​​that are complements of languages ​​belonging to the class NP. It is not known whether coNP is different from NP.

P 与 NP 问题

P versus NP Issue

正如我们所说,NP是一类可以由非确定性图灵机在多项式时间内判定的语言;等价地,可以说它是一类可以在多项式时间内验证单词是否属于某种语言的语言。反过来,P 是一类语言,可以在多项式时间内检查其语言从属关系。我们可以将其总结如下,使用术语“快速”作为短语“多项式时间可解”的松散等价物。

As we said, NP is the class of languages ​​that are decidable in polynomial time by nondeterministic Turing machines; equivalently, it is the class of languages ​​for which a word can be verified to be a member of the language in polynomial time. In turn, P is the class of languages ​​for which a word can be verified to be a member of the language in polynomial time. We can summarize this as follows, using the term "fast" as a loose equivalent of "solvable in polynomial time."

P = 一类语言,可以快速解决单词与语言的从属关系。

P = class of languages ​​for which the language affiliation of a word can be quickly decided .

NP = 可以快速验证单词的语言隶属关系的一类语言。

NP = class of languages ​​for which the language belonging of a word can be quickly verified .

我们提供了HAMPATHCLIQUE等属于 NP 类的语言的例子,但不知道它们是否属于 P 类。多项式验证的可能性似乎比多项式可判定性的可能性要远得多。虽然很难想象,但 P 类和 NP 类是可能相等的。我们(到目前为止)无法证明甚至存在一种属于 NP 类但不属于 P 类的语言。

We have given examples of languages ​​such as HAMPATH and CLIQUE , which are in the class NP but are not known to be in the class P. The possibility of polynomial verification seems to go much further than the possibility of polynomial decidability. Although it is hard to imagine, it is possible that the classes P and NP are equal. We cannot (yet) prove the existence of a single language that is in the class NP but not in the class P.

P = NP 是否是理论计算机科学和现代数学中最大的未解决问题之一。如果这些类相等,则每个多项式可验证问题也将是多项式可判定的。大多数研究人员认为这些类别是不平等的,因为人们为寻找 NP 类别中某些问题的多项式时间算法付出了巨大的努力,但没有成功。科学家们还试图证明这些类别是不相等的,但这需要证明没有快速算法可以取代暴力搜索。至少现在,这也超出了科学的范围。下图显示了两种可能性。

The question of whether P = NP is one of the greatest unsolved problems in theoretical computer science and modern mathematics. If these classes were equal, every polynomially verifiable problem would also be polynomially decidable. Most researchers believe that these classes are not equal, because a huge amount of effort has been put into finding polynomial-time algorithms for some problems in the class NP, without success. Scientists have also tried to prove that these classes are not equal, but this would require proving that there are no fast algorithms to replace brute-force search. At least at present, this is also beyond the capabilities of science. The figure below shows both possibilities.

7.26

这两种可能性之一是正确的

Figure 7.26

One of these two possibilities is correct

目前已知的最好的 NP 语言确定性解析方法需要指数时间。换句话说,我们可以证明

The best currently known methods for deterministically resolving NP-class languages ​​require exponential time. In other words, we can prove that

但我们不知道 NP 类是否包含在确定性时间复杂度的某个较小的类中。

but we do not know whether the class NP is contained in some smaller class of deterministic time complexity.

7.4

NP完备性

7.4

NP-completeness

在 20 世纪 70 年代初期,斯蒂芬·库克 (Stephen Cook) 和列昂尼德·莱文 (Leonid Levin) 的工作在 P 与 NP 问题上取得了重大进展。他们发现了一些属于NP类的问题,其个体复杂度与整个类的复杂度相关。如果任何这些问题都存在多项式时间算法,则所有 NP 问题都可以在多项式时间内解决。这些问题被称为NP 完备问题。 NP 完备性现象在理论和实践上都很重要。

Significant progress on the P versus NP question came in the early 1970s with the work of Stephen Cook and Leonid Levin. They discovered certain problems in the class NP whose individual complexity is related to the complexity of the class as a whole. If there is a polynomial-time algorithm for any of these problems, then all problems in the class NP are solvable in polynomial time. These problems are called NP-complete . The phenomenon of NP-completeness is important for both theoretical and practical reasons.

在理论方面,试图证明 P 类不等于 NP 类的研究人员可能会关注 NP 完备问题。如果任何 NP 问题需要超过多项式时间,那么每个 NP 完备问题也需要(至少)这个时间。此外,试图证明 P 类和 NP 类相等的研究人员只需要为任何 NP 完备问题找到一个多项式算法即可实现此目标。

On the theoretical side, a researcher trying to show that the class P is not equal to the class NP can focus on NP-complete problems. If any problem in the class NP requires more than polynomial time, then any NP-complete problem also requires (at least) polynomial time. Moreover, a researcher trying to prove that the classes P and NP are equal need only find a polynomial algorithm for any NP-complete problem to achieve this goal.

从实践的角度来看,NP完备性现象可以使我们免于浪费时间寻找不存在的多项式算法来解决特定问题。即使我们没有足够的数学技能来证明一个问题在多项式时间内无法解决,我们也相信 P 类不等于 NP 类。因此,表明问题是 NP 完备的就有力地表明它不是多项式。

On the practical side, NP-completeness can save us from wasting time looking for a nonexistent polynomial-time algorithm to solve some particular problem. Even if we do not have the mathematical skills to prove that a problem is unsolvable in polynomial time, we believe that the class P is not equal to the class NP. Thus, showing that a problem is NP-complete is a strong indication that it is not polynomial.

我们要介绍的第一个 NP 完备问题是可满足性问题。让我们回想一下,具有 TRUE 和 FALSE 值的变量称为逻辑布尔)变量;它们在 0.2 小节中进行了描述。通常,我们将 TRUE 写为 1,将 FALSE 写为 0。逻辑(布尔)运算AND、OR 和 NOT 分别由符号Ø表示,如下所示。我们使用变量符号上方的破折号简单地写出否定,因此x表示 Ø x

The first NP-complete problem we will present is the satisfiability problem . Recall that variables that take on the values ​​TRUE and FALSE are called logical ( Boolean ) variables; they are described in Section 0.2. We usually write TRUE as 1 and FALSE as 0. The logical ( Boolean ) operations AND, OR, and NOT, represented by the symbols , , and ¬ , respectively , are shown below. Negation is abbreviated by using a line over the variable's sign, so x denotes ¬ x .

0 0 = 0 0 0 = 0 0 = 1

0 0 = 0 0 0 = 0 0 = 1

0 1 = 0 0 1 = 1 1 = 0

0 1 = 0 0 1 = 1 1 = 0

1 0 = 0 1 0 = 1

1 0 = 0 1 0 = 1

1 1 = 1 1 1 = 1

1 1 = 1 1 1 = 1

逻辑布尔)公式是由变量和逻辑运算组成的表达式。例如

A logical ( Boolean ) formula is an expression built from variables and logical operations. For example

Φ = ( x y ) ( x z )

Φ = ( x y ) ( x z )

是一个逻辑公式。如果将值 0 和 1 分配给变量(称为变量求值),使得公式返回值 1(真),则逻辑公式是可满足的。前面的公式是可满足的,因为赋值x = 0、y = 1 和 z = 0 导致φ的值等于 1。然后我们说这个估值满足 Φ。可满足性问题涉及检查给定的逻辑公式是否可满足。让

is a logical formula. A logical formula is satisfiable if there is some assignment of the values ​​0 and 1 to variables (called a valuation of variables) such that the formula gives the value 1 (true). The preceding formula is satisfiable, since the assignment x = 0, y = 1 and z = 0 causes the value φ to be equal to 1. We then say that this valuation satisfies Φ . The satisfiability problem consists in checking whether a given logical formula is satisfiable. Let

SAT = { 〈Φ〉 : Φ是可满足的逻辑公式 }。

SAT = { 〈Φ〉 : Φ is a satisfiable logical formula }.

我们现在将制定一个定理,将SAT问题的复杂性与属于 NP 类的所有问题的复杂性联系起来。

We now formulate a theorem that relates the complexity of the SAT problem to the complexity of all problems belonging to the class NP.

定理7.27

Theorem 7.27

SAT P 当且仅当 P = NP。

SAT P if and only if P = NP.

现在我们转向推导证明该定理的关键技术。

We now turn to deriving the techniques key to proving this theorem.

多项式时间的可约性

Reducibility in polynomial time

在第五章中,我们定义了将一个问题简化为另一个问题的概念。当问题A简化为问题B时,我们可以用问题B的解来解决问题A。我们现在将定义一个考虑到计算效率的可归约变体。如果问题A可以有效地简化为问题B ,则可以使用问题B的有效解来获得问题A的有效解。

In Chapter 5 we defined the notion of reduction of one problem to another. If problem A is reducible to problem B , then we can use the solution to problem B to solve problem A . We now define a variant of reducibility that takes into account the efficiency of the computations performed. If problem A is efficiently reducible to problem B , then we can use an efficient solution to problem B to obtain an efficient solution to problem A .

定义 7.28

Definition 7.28

函数f : Σ * Σ * 是一个多项式时间可计算函数,或者简称为多项式可计算函数,如果存在某个多项式时间图灵机M,当它针对输入字w 启动时,以值f停止(w ) 印在胶带上。

A function f : Σ * Σ * is a polynomial-time computable function , or in short polynomial-computable , if there exists some polynomial-time Turing machine M that, when started for an input word w, halts with the value f ( w ) written to the tape.

定义 7.29

Definition 7.29

如果存在多项式可计算函数f : Σ * Σ * ,使得对于每个w

A language A is reducible by a polynomial - time mapping 1 , or simply polynomially reducible to a language B , which we write AP B , if there exists a polynomially computable function f : Σ * Σ *, such that for every w

w A f ( w ) B

w A f ( w ) B .

函数f称为AB多项式约简。

The function f is called the polynomial reduction of A to B .

多项式约简是第 5.3 节中定义的映射约简的有效等价物。还有其他形式的有效约简,但多项式约简很简单并且足以满足我们的目的,因此我们不会在这里讨论其他形式。多项式可约性如图 7.30 所示。

Polynomial reduction is an efficient analogue of reduction by mapping defined in Section 5.3. There are other forms of efficient reducibility, but polynomial reduction is simple and sufficient for our purposes, so we will not discuss other forms here. Polynomial reducibility is illustrated in Figure 7.30.

7.30将A约简为B 的多项式时间可计算

函数f

Figure 7.30

A function f computable in polynomial time that reduces A to B

与普通的映射归约一样,从AB 的多项式归约允许您将某个单词是否属于语言A的问题替换为该单词是否属于语言B 的问题,但这次交换是高效执行的。为了检查w是否 A,我们使用约简fw映射到f ( w ) ,然后检查f ( w )是否 B 。

Like the usual reduction by mapping, the polynomial reduction from A to B allows us to turn the question of whether a certain word belongs to language A into the question of whether it belongs to language B , but this time the conversion is done efficiently. To check whether w A , we use the reduction f to map w to f ( w ), and then check whether f ( w ) B .

如果某种语言可以多项式约简为已知多项式时间解的语言,那么我们获得原始语言的多项式时间解,如以下定理所示。

If a language is polynomially reducible to a language for which a polynomial-time solution is already known, then we obtain a polynomial-time solution to the original language, as in the following theorem.

定理7.31

Theorem 7.31

如果AP BB P,则A P。

If AP B and B P, then A P.

证明 M为求解B 的多项式算法,并设f为从AB 的多项式约简解析语言A 的N多项式算法

Proof Let M be a polynomial-time algorithm for deciding B , and let f be a polynomial reduction from A to B . We describe the following polynomial-time algorithm N for deciding the language A .

N =“对于中的输入词:

N = "For input word in :

  1. 计算f ( w )。
  2. Calculate f ( w ).
  3. 针对输入字f ( w )运行机器M并返回机器M返回的结果。
  4. Start machine M for input word f ( w ) and return what machine M " returns.

我们知道w A当且仅当f ( w ) B,因为f是从AB的约简。因此,只要w A , M就接受f ( w ) 。此外,N以多项式时间运行,因为它的两个步骤中的每一个都需要这个时间。请注意,步骤 2 在多项式时间内运行,因为两个多项式的复合是一个多项式。

We know that w A if and only if f ( w ) B , since f is a reduction from A to B . Thus, M accepts f ( w ) whenever w A . Moreover, N runs in polynomial time, since each of its two steps takes polynomial time. Note that step 2 runs in polynomial time, since the composition of two polynomials is a polynomial.

在展示第一个多项式约简示例之前,我们先介绍3SAT问题,这是可满足性问题的一个变体,其中所有公式都采用某种特殊形式。文字是逻辑变量或否定逻辑变量,例如xx子句是由∨运算符连接的多个文字,例如 ( x 1 x 2 x 3 x 4 )。逻辑公式合取范式,简称CNF形式(合取范式) ,如果它由一系列由连词连接的子句组成,例如

Before we show the first example of polynomial reduction, we introduce the 3SAT problem , a variant of the satisfiability problem in which all formulas are in some special form. A literal is a Boolean variable or negated Boolean variable, such as x or x . A clause is several literals connected by the operators , for example ( x 1 x 2 x 3 x 4 ). A Boolean formula is in conjunctive normal form , called CNF for short , if it consists of a series of clauses connected by the connectives , for example

( x 1 x 2 x 3 x 4 ) ( x 3 x 5 x 6 ) ( x 3 x 6 )。

( x 1 x 2 x 3 x 4 ) ( x 3 x 5 x 6 ) ( x 3 x 6 ).

例如,如果所有子句都包含三个文字,则公式的形式为3CNF

A formula is in 3CNF if all clauses contain three literals, for example

( x 1 x 2 x 3 ) ( x 3 x 5 x 6 ) ( x 3 x 6 x 4 ) ( x 4 x 5 x 6 )。

( x 1 x 2 x 3 ) ( x 3 x 5 x 6 ) ( x 3 x 6 x 4 ) ( x 4 x 5 x 6 ).

3SAT = { 〈Φ〉Φ是 3CNF} 形式的可满足公式。如果变量求值满足CNF公式,则每个子句必须至少包含一个值为1的文字。

Let 3SAT = { 〈Φ〉 : Φ be a 3CNF-satisfiable formula. If the evaluation of variables satisfies CNF, then each clause must contain at least one literal whose value is 1.

以下定理显示了3SAT问题到CLIQUE问题的多项式约简。

The following theorem shows a polynomial reduction of the 3SAT problem to the CLIQUE problem .

定理7.32

Theorem 7.32

3SAT问题可以通过多项式时间简化为CLIQUE问题。

The 3SAT problem is reducible in polynomial time to the CLIQUE problem .

证明概念3SATCLIQUE问题 多项式约简f将公式转换为图形。在构造图中,一定大小的团对应于公式中变量的满足值。图结构旨在模仿变量和子句的行为。

Proof Concept The polynomial reduction f of the 3SAT problemto CLIQUE transforms formulas into graphs. In the constructed graphs, cliques of a given size correspond to satisfying valuations of variables in the formula. The graph structure is designed to mimic the behavior of variables and clauses.

证明 Φ为包含k 个子句的公式,例如

Proof Let Φ be a formula with k clauses such as

Φ = ( a 1 b 1 c 1 ) ( a 2 b 2 c 2 ) ( a k b k c k )。

Φ = ( a 1 b 1 c 1 ) ( a 2 b 2 c 2 ) ( a k b k c k ).

约简f生成单词G , k ,其中G是定义如下的无向图。

The reduction f generates a word G , k , where G is an undirected graph defined as follows.

图G的顶点排列成k组,每组三个顶点,称为三元组, t 1 , ..., t k。每个三元组对应于属于Φ的子句之一,并且三元组中的每个顶点对应于相应子句中的文字。我们用Φ中相应的文字标记图G的每个节点。图G的边连接除两种类型之外的所有顶点对。同一三元组中的顶点之间不存在边,并且没有边连接具有相反标签的节点,例如x 2x 2Φ = ( x 1 x 1 x 2 ) ( x 1 x 2 x 2 ) ( x 1 x 2 x 2 )的构造如图 7.33 所示。

The vertices of G are arranged into k groups of three vertices each, called triples , t 1 , …, t k . Each triple corresponds to one of the clauses in Φ , and each vertex in the triple corresponds to a literal from the corresponding clause. Each node of G is labeled with the corresponding literal in Φ . The edges of G connect all pairs of vertices except for two types. No edge occurs between vertices in the same triple, and no edge connects nodes with opposite labels, for example x 2 and x 2 . This construction for Φ = ( x 1 x 1 x 2 ) ( x 1 x 2 x 2 ) ( x 1 x 2 x 2 ) is shown in Figure 7.33.

7.33

根据公式Φ = ( x 1 x 1 x 2 ) ( x 1 x 2 x 2 ) ( x 1 x 2 x 2 )进行归约创建的图形

Figure 7.33

The graph generated by reduction with the formula Φ = ( x 1 x 1 x 2 ) ( x 1 x 2 x 2 ) ( x 1 x 2 x 2 )

现在我们将解释为什么这种设计有效。我们将证明当且仅当图G包含k团时,公式Φ是可满足的。

We now explain why this construction works. We show that the formula Φ is satisfiable if and only if the graph G contains a k -clique.

假设Φ具有令人满意的估值。在此评估中,每个子句中至少有一个文字必须评估为 TRUE。在图G中的每个三元组中,我们选择与满足评估中值为 TRUE 的文字对应的顶点。如果某个子句中多个文字的计算结果为 TRUE,我们会任意选择其中一个。刚刚选择的顶点形成k团。所选顶点的数量为k,因为我们从k 个三元组中每一个选择了一个。当这些对中没有一个与前面描述的例外情况匹配时,每对选定的顶点都通过一条边连接。它们不能来自同一个三元组,因为我们从每个三元组中选择了一个顶点。它们不能有相反的标签,因为在令人满意的评估中所有相应的文字都是 TRUE。所以我们已经证明图G包含一个 k团。

Suppose Φ has a satisfying valuation. In this valuation, at least one literal in each clause must be TRUE. In each triple in the graph G, we choose a vertex corresponding to a literal that is TRUE in the satisfying valuation. If more than one literal is TRUE in a clause, we choose one of them at random. The vertices we have just chosen form a k -clique. The number of selected vertices is k , because we have chosen one from each of the k triples. Each pair of selected vertices is connected by an edge if none of these pairs fits the exceptions described earlier. They cannot come from the same triple, because we have chosen one vertex from each triple. They cannot have opposite labels, because all of their corresponding literals are TRUE in the satisfying valuation. We have thus shown that the graph G contains a k -clique.

现在假设图G包含k团。团中的两个顶点不能属于同一个三元组,因为同一三元组中的顶点不通过边连接。因此,k 个三元组中的每一个恰好包含该团的k 个顶点之一。我们为Φ变量赋值,使得 clique 的顶点标签中的每个文字都接收到值 TRUE。这是可能的,因为具有相反标签的两个顶点不会通过边连接,因此不能同时位于团中。该变量评估满足公式Φ,因为每个三元组都包含团的一个顶点,因此每个子句都包含一个赋值为 TRUE 的文字。因此,公式Φ是可满足的。

Now suppose that the graph G contains a k -clique. No two vertices in a clique can belong to the same triple, since no vertices in the same triple are connected by edges. Thus, each of the k triples contains exactly one of the k vertices of the clique. We assign values ​​to the variables Φ in such a way that each literal of the vertex labels of the clique is given the value TRUE. This is possible because no two vertices with opposite labels are connected by an edge, and thus cannot both be in a clique. This evaluation of the variables satisfies the formula Φ , since every triple contains a vertex of the clique, and therefore every clause contains a literal with the value TRUE. Thus, the formula Φ is satisfiable.

定理 7.31 和 7.32 表明,如果CLIQUE问题在多项式时间内可解,则3SAT问题也是可解的。乍一看,这些问题之间的联系似乎很不可思议,因为它们似乎有根本的不同。尽管如此,多项式约简使我们能够将它们的复杂性联系起来。现在我们转向一个定义,它将使我们能够以类似的方式将整类问题的复杂性联系起来。

Theorems 7.31 and 7.32 say that if the CLIQUE problem is polynomial-time solvable, then the 3SAT problem is polynomial-time solvable as well. At first glance, this connection between these problems seems rather uncanny, since they seem to be essentially different. Nevertheless, polynomial reduction allows us to relate their complexities. We now turn to a definition that allows us to relate the complexities of a whole class of problems in a similar way.

NP 完备性的定义

Definition of NP-completeness

定义 7.34

Definition 7.34

如果语言B满足以下两个条件,则称为NP 完备语言:

A language B is called NP-complete if it satisfies the following two conditions:

  1. B属于NP类。
  2. B belongs to class NP.
  3. 属于NP的每种语言A都可以多项式简化为B。
  4. Every language A in NP is polynomially reducible to B .

定理7.35

Theorem 7.35

如果语言B是 NP 完备的且B P,则 P = NP。

If the language B is NP-complete and B P, then P = NP.

证明 该定理直接从多项式时间约简的定义得出。

Proof This theorem follows directly from the definition of reduction in polynomial time.

定理7.36

Theorem 7.36

如果语言B是 NP 完备的,并且对于NP 类的某些语言C , BP C ,则C是 NP 完备的。

If a language B is NP-complete and BP C for some language C of class NP, then C is NP-complete.

证明 我们已经知道C属于NP类,所以我们需要证明NP类中的每种语言A都可以多项式时间约简到语言C。由于语言B是 NP 完备的,因此 NP 类中的每种语言都可以多项式还原为B ,而B又可以多项式还原为C 。多项式时间约简可以组合,即,如果语言A多项式可约简到语言BB多项式可约简到语言C,则A多项式可约简到C 。因此,任何属于 NP 类的语言都可以在多项式时间上简化为C。

Proof We already know that C is in the class NP, so we need to show that every language A in the class NP is polynomial-time reducible to the language C . Since the language B is NP-complete, every language in the class NP is polynomial-time reducible to B , and in turn B is polynomial-time reducible to C . Polynomial-time reductions are composable, that is, if the language A is polynomial-time reducible to B and B is polynomial-time reducible to C , then A is polynomial-time reducible to C . Therefore, every language in the class NP is polynomial-time reducible to C .

库克-莱文定理

Cook-Levin theorem

一旦我们有了一个 NP 完备问题,我们就能够通过该问题的多项式约简来获得其他问题。然而,找到第一个 NP 完备问题更加困难。现在我们将通过证明SAT问题是 NP 完备问题来实现这一点。

Once we have one NP-complete problem, we can get others by polynomial reduction from that problem. However, finding that first NP-complete problem is harder. We will do that now by showing that the SAT problem is NP-complete.

定理7.37

Theorem 7.37

SAT问题是 NP 完备问题2

The SAT problem is NP-complete 2 .

这是定理 7.27 的另一种表述。

This is another formulation of Theorem 7.27.

证明的概念 证明SAT属于 NP 类很容易,我们稍后将展示这一点。证明的困难部分是证明 NP 类中的任何语言都可以多项式简化为SAT

Concept of the Proof Showing that SAT is in NP is easy, and we'll show it in a moment. The hard part of the proof is showing that any language in NP is polynomially reducible to SAT .

为此,我们将为属于 NP 类的每种语言A构建SAT问题的多项式时间约简。语言A的约简将单词w作为输入,并生成一个逻辑公式Φ ,该公式模拟语言A和输入单词w的 NP 机。如果机器接受,则Φ具有满足与接受机器的计算路径相对应的评估。如果机器不接受,则没有估价满足公式Φ。因此,当且仅当Φ是可满足公式时,w属于语言A。

To this end, we construct a polynomial-time reduction to the SAT problem for any language A in the class NP. The reduction for language A takes as input a word w and produces a Boolean formula Φ that simulates an NP machine for language A and input word w . If the machine accepts, then Φ has a valuation that satisfies the machine's accepting computation path. If the machine does not accept, then no valuation satisfies the formula Φ . Thus w belongs to language A if and only if Φ is a satisfiable formula.

构建以这种方式工作的约简在概念上是一项简单的任务,尽管它涉及许多细节。逻辑公式可能包含 AND、OR 和 NOT 运算符,这些运算构成了计算机构造中使用的电路的基础。因此,我们可以构建一个模拟图灵机的逻辑公式也就不足为奇了。实施这个想法时,细节决定成败。

Constructing a reduction that works in this way is a conceptually simple task, although it involves a lot of detail. A logical formula can contain the AND, OR, and NOT operators, and it is these operations that form the basis of the electrical circuits used in building computers. It is not surprising, then, that we can construct a logical formula that simulates a Turing machine. The devil is in the details in implementing this idea.

证明 首先,我们需要证明SAT问题属于NP类。非确定性多项式时间图灵机可以猜测给定公式Φ的评估,并在评估满足Φ 的情况下接受它。

Proof We first need to show that the SAT problem is in NP. A nondeterministic polynomial-time Turing machine can guess a valuation for a given formula Φ and accept it if that valuation satisfies Φ .

然后,我们将采用属于 NP 类的任何语言A并证明A可以多项式约简为SAT。令N为非确定性图灵机,它在时间n k上针对某个常数k解析语言A。(为了方便起见,我们假设机器N在n k − 3时间内运行,但只有那些次要细节的读者才应该关心这个次要细节。)下面提出的概念将帮助我们描述这种减少。

We then take any language A of the class NP and show that A is polynomially reducible to SAT . Let N be a nondeterministic Turing machine that decides A in time n k for some constant k . (For convenience, we assume that N runs in time n k − 3, but this minor detail should concern only those readers who care about fine details.) The following concepts will help us describe this reduction.

机器N和单词w 的表格是一个n k × n k表,其中每一行包含输入单词w的某个计算路径N的配置,如下图所示。

The tableau for a machine N and a word w is an n k × n k table , where each row contains the configuration of some computation path N for input word w , as shown in the figure below.

为了方便起见,我们假设每个配置都以 # 符号开始和结束。因此,表格的第一列和最后一列仅包含 # 字符。表的第一行是机器N对单词w的初始配置,后续的每一行根据机器N的转换函数从前一行开始。如果任何行包含接受配置,则Tableau 正在接受。

For convenience in the following considerations, we will assume that each configuration begins and ends with the symbol #. Thus, the first and last columns of the tableau contain only the characters #. The first row of the tableau is the initial configuration of machine N for word w , and each subsequent row follows from the previous one according to the transition function of machine N . The tableau is accepting if any row contains an accepting configuration.

7.38 Tableau是一个n k × n k

的配置数组

Figure 7.38 Tableau is an n k × n k

configuration table.

机器N对词w的每个接受表对应于机器N对词w的接受计算路径。这意味着判断N是否接受w的问题等价于判断机器N是否存在对单词w的接受表的问题。

Each accepting tableau of machine N for word w corresponds to an accepting computation path of machine N for word w . That is, the problem of determining whether N accepts w is equivalent to the problem of determining whether there is an accepting tableau of machine N for word w .

我们现在可以继续描述fASAT的多项式约简。对于输入词w,缩减函数生成公式Φ。我们将从描述变量Φ开始。令QГ分别为机器N的状态集和磁带字母表。设C = Q Γ {#}。我们为1 到n k范围内的所有i和 j以及每个s C创建变量x ijs

We can now proceed to describe the polynomial reduction f from language A to SAT . For an input word w , the reduction function produces a formula Φ . We start by describing the variables Φ . Let Q and Γ be the set of states and the tape alphabet of machine N , respectively . Let C = Q Γ {#}. We create variables x i , j , s for all i and  j in the range 1 to n k and for all s C .

表中的每个 ( n k ) 2 个条目称为一个单元。我们将第ij列的单元格表示为单元格[i, j ];它包含集合C中的一个符号。我们将用公式变量Φ表示各个单元格的内容。如果x i , j , s取值为 1,则表示单元格[i, j ] 中有符号s

Each of the ( n k ) 2 entries in the tableau is called a cell . The cell in row i and column j is denoted cell [i, j ]; it contains one symbol from the set C . The contents of the individual cells will be represented by the formula variables Φ . If x i , j , s takes the value 1, it means that cell [i, j ] contains the symbol s .

我们现在将构造Φ,以便变量的令人满意的评估对应于机器N对单词w的接受表。公式Φ是四部分的合取:Φ cell Φ start Φ move Φ Accept。我们现在将一一描述它们。

We now construct Φ such that the satisfying evaluation of the variables corresponds to the accepting tableau of machine N for the word w . The formula Φ is a conjunction of four parts: Φ cell Φ start Φ move Φ accept . We now describe them in turn.

正如我们之前提到的,“设置”变量x i , j , s,即将其设置为 1,对应于将符号s放入单元格[i, j ]中。我们需要确保实现赋值和表格之间的对应关系的第一件事是赋值为每个单元格设置了一个变量。Φ单元格公式可确保满足此条件,如下所示:

As we mentioned earlier, “setting” a variable x i , j , s , i.e. setting its value to 1, is equivalent to placing the symbol s in cell [i, j ]. The first thing we need to ensure in order to achieve a correspondence between assignment and tableau is that the assignment sets exactly one variable for each cell. The formula Φ cell ensures this as follows:

这里的符号表示 AND 和 OR 运算符的迭代。例如,前面公式中的表达式

The symbols and here denote iterations over the AND and OR operators. For example, the expression in the previous formula

是一个缩写符号

is a shorthand notation

其中C = { s 1 , s 2 , …, s l }。由此可见,Φ只是一个大表达式,其中包含表中每个单元格的适当块,因为索引i和 j从 1 到n k运行。每个此类片段的第一部分要求为相应的单元设置至少一个变量。每个片段的第二部分要求在相应的单元格中设置不超过一个变量(从字面上讲,它要求对于每一对变量至少有一个未设置)。这些片段通过连词连接起来。

where C = { s 1 , s 2 , …, s l }. It follows that Φ is simply a large expression containing the corresponding fragment for each cell in the table, as the indices i and  j run from 1 to n k . The first part of each such fragment requires that at least one variable be set for the corresponding cell. The second part of each fragment requires that no more than one variable in the corresponding cell be set (literally speaking, it requires that for each pair of variables at least one be unset). These fragments are connected by a conjunction.

方括号内的Φ cell的第一部分指定至少设置一个与每个单元格关联的变量,第二部分指定为每个单元格设置不超过一个变量。满足Φ(因此也满足Φ cell )的任何变量评估必须恰好包含每个单元格的一个变量。因此,任何令人满意的评估都为表格中的每个单元格指定一个符号。

The first part of Φ cell inside the square brackets specifies that at least one variable associated with each cell is set, while the second part specifies that no more than one variable is set for each cell. Any valuation of variables that satisfies Φ (and hence Φ cell ) must contain exactly one variable for each cell. Thus, any valuation that satisfies specifies exactly one symbol for each cell in the tableau.

如下所述,Φ startΦ moveΦ Accept部分确保这些符号对应于接受画面。

The Φ start , Φ move , and Φ accept parts guarantee, as described below, that these symbols correspond to an accepting tableau.

Φ启动公式通过明确指示设置了适当的变量,保证表的第一行是机器N对于单词w的启动配置:

The formula Φ start ensures that the first row of the tableau is the initial configuration of machine N for word w , explicitly indicating that the appropriate variables are set:

Φ接受公式确保画面具有接受配置。它确保q Accept(接受状态符号)出现在表格单元格之一中,从而强制设置相应变量之一:

The formula Φ accept guarantees that there is an accepting configuration in the tableau. It ensures that q accept , the symbol of the accepting state, appears in one of the tableau cells by imposing the setting of one of the corresponding variables:

最后,Φ 移动公式确保表格的每一行都对应于根据机器N的传递函数从前一行描述的配置中正确得出的配置。它通过确保每个 2×3 窗口的表格单元格都是正确的来实现这一点。如果窗口中没有任何内容违反传递函数N中指定的操作,我们就说 2 × 3 窗口是有效的。换句话说,如果一个配置正确遵循前3 个配置,则该窗口可以出现,则该窗口是有效的。

Finally, the formula Φ move guarantees that each row of the tableau corresponds to a configuration that correctly follows from the configuration described in the preceding row according to the transition function of the machine N . It does this by ensuring that each 2 × 3 window of tableau cells is valid. We say that a 2 × 3 window is valid if there is nothing in that window that violates the operations specified in the transition function N . In other words, a window is valid if it could have appeared if one configuration correctly followed from the previous 3 .

例如,假设abc是磁带字母表的符号,q 1q 2是机器N的状态。让我们假设当处于状态q 1 的机器N读取字符a时,它将字符b写入磁带,保持在状态q 1并将磁头向右移动。如果处于状态q 1 的机器读取字符b,它将不确定地执行以下移动之一:

For example, suppose that a , b , and c are symbols of the tape alphabet, and q 1 and q 2 are states of machine N . Suppose that when machine N in state q 1 reads character a , it writes character b to the tape , remains in state q 1 , and moves the head to the right. If the machine in state q 1 reads character b , it nondeterministically performs one of the following moves:

  1. 保存c,进入状态q 2并将头部向左移动,
  2. writes c , enters state q 2 and moves the head to the left,
  3. 保存a,进入状态q 2并将头部向右移动。
  4. writes a , enters state q 2 and moves the head to the right.

形式上,它可以表示为: δ( q 1 , a ) = {( q 1 , b , R )} 和 δ( q 1 , b ) = {( q 2 , c , L ), ( q 2 ,一个R)}。该机器的有效窗口示例如图 7.39 所示。

Formally, this can be expressed as follows: δ( q 1 , a ) = {( q 1 , b , R )} and δ( q 1 , b ) = {( q 2 , c , L ), ( q 2 , a , R )}. Examples of valid windows for this machine are shown in Figure 7.39.

7.39

有效窗口示例

Figure 7.39

Examples of correct windows

在图 7.39 中,窗口 (a) 和 ( b ) 是正确的,因为传递函数允许N以指定的方式移动。窗口 ( c ) 是正确的,因为q 1出现在顶行的右侧,我们不知道头部读取的是什么符号。该符号可以是a,然后q 1可以将其更改为b并将头部向右移动。这种可能性会导致如图( c )所示的窗口,因此它不违反机器N的传递函数。窗口( d )显然是正确的,因为顶行和底行是相同的,这对应于头部不位于与窗口位置相邻的位置的情况。另请注意,# 符号可能出现在有效窗口的两行(顶部和底部)的左侧或右侧。窗口 ( e ) 是正确的,因为状态q 1读取符号b可能位于紧邻顶行右侧的单元中,该单元将向左移动到状态q 2,状态 q 2 出现在底行的右端。最后,窗口 ( f ) 是正确的,因为状态q 1可以直接位于顶行的左侧,看到窗口左上角的符号,这可能导致b更改为c并将头部移动到左边。

In Figure 7.39, windows (a) and ( b ) are correct, since the transition function allows N to move in the way indicated. Window ( c ) is correct, since with q 1 appearing on the right side of the top row, we do not know what symbol the head is reading. This symbol could be a , and q 1 could then change it to b and move the head to the right. This possibility would produce the window shown in Figure ( c ), so it does not violate the transition function of machine N. Window ( d ) is of course correct, since the top and bottom rows are identical, which corresponds to the case when the head is not in a location adjacent to the window. Note also that the symbol # can appear on either the left or the right side of both rows (top and bottom) of a correct window. Window ( e ) is correct because state q 1 reading symbol b could be in the cell immediately to the right of the top row, which would cause a left shift to state q 2 , which is visible at the right end of the bottom row. Finally, window ( f ) is correct because state q 1 could be immediately to the left of the top row, seeing the symbol in the upper left corner of the window, which would cause b to change to c and the head to move left.

下图显示了机器N的无效窗口。

The next figure shows invalid windows for machine N .

7.40

无效窗口示例

Figure 7.40

Examples of invalid windows

在窗口(a)中,顶行的中间符号不能改变,因为没有与其相邻的状态。窗口 ( b ) 无效,因为转换函数指定b可以更改为c,但不能更改为a。窗口 ( c ) 无效,因为底行有两种状态。

In window (a), the middle symbol in the top row cannot change because it has no adjacent states. Window ( b ) is not valid because the transition function specifies that b can change to c but not to a . Window ( c ) is not valid because there are two states in the bottom row.

声明 7.41

Statement 7.41

如果表格的顶行是初始配置,并且表格中的每个窗口都是正确的,则表格的每一行都是根据前一行中包含的配置正确得出的配置。

If the top row of the tableau is the initial configuration and every window in the tableau is valid, then each row of the tableau is a configuration that results correctly from the configuration contained in the previous row.

我们将通过考虑表格中的任意两个相邻配置(我们将其称为顶部和底部)来证明这一说法。在顶部配置中,任何包含磁带符号且没有相邻状态符号的单元都是窗口的顶部中间单元,其顶行不包含状态。因此,该符号在窗口中下单元格中必须保持不变。这意味着它出现在较低配置中的相同位置。

We prove this statement by considering any two adjacent configurations in the tableau, which we will call the upper and lower configurations. In the upper configuration, any cell containing a tape symbol that is not adjacent to a state symbol is the upper-middle cell of the window, whose top row contains no states. Thus, this symbol must appear unchanged in the lower-middle cell of the window. That is, it appears in the same position in the lower configuration.

顶部中心单元格中包含状态符号的窗口确保相应的三个项目根据转换函数而改变。因此,如果上面的配置是正确的,那么下面的配置也是正确的,并且后者根据机器的传递函数N由前者得出。请注意,这个证明虽然非常简单,但很大程度上取决于所选的 2 × 3 窗口大小,如我们将在问题 7.41 中所示。

The window containing the state symbol in the top-middle cell guarantees that the corresponding three positions will be changed according to the transition function. Thus, if the top configuration is correct, so is the bottom configuration, and the latter follows from the first according to the transition function of the machine N . Note that this proof, although very simple, depends significantly on the chosen window size of 2 × 3, as we will show in Problem 7.41.

现在让我们回到Φ move的构造。这表明tableau中的所有窗口都是正确的。每个窗口包含六个单元格,可以通过有限数量的方式填充符号以获得有效窗口。Φ移动公式表示这六个单元格的设置必须是正确设置之一,即

Let us now return to the construction of Φ move . It follows that all windows in the tableau are valid. Each window contains six cells that can be filled with symbols in a finite number of ways to obtain a valid window. The formula Φ move says that the arrangement of these six cells must be one of the valid arrangements, that is,

窗口 ( i , j ) 是一个包含单元格[ i, j ] 作为其顶部中间位置的窗口。我们用以下表达式替换该公式中的短语“窗口( i , j ) 有效”。六个窗口单元内容写为1、... 6

Window ( i , j ) is a window containing cell cell [ i, j ] as the top middle position. We replace the phrase "window ( i , j ) is valid" in this formula with the following expression. We write the contents of the six cells of the window as a 1 , …, a 6 .

我们现在分析这种简化的复杂性,以表明它在多项式时间内有效。为此,我们将确定公式Φ的大小。首先我们需要估计它包含的变量数量。回想一下,tableau 是一个n k × n k数组,因此它包含n 2 k个单元。每个单元有l 个与之相关的变量,其中l是集合C的符号数量。由于l仅取决于图灵机N ,而不取决于输入字n的长度,因此变量总数为O ( n 2 k )。

We will now analyze the complexity of this reduction to show that it runs in polynomial time. To do this, we will determine the size of the formula Φ . First, we need to estimate the number of variables it contains. Recall that the tableau is an n k × n k table , so it contains n 2 k cells. Each cell has l variables associated with it, where l is the number of symbols in the set C . Since l depends only on the Turing machine N , and not on the length of the input word n ​​, the total number of variables is O ( n 2 k ).

我们将估计Φ每个部分的大小。公式Φ cell包含每个表格单元格的固定长度片段,因此其大小为O ( n 2 k )。Φ起始公式包含顶行中每个单元格的固定大小块,因此其大小为O ( n k )。Φ moveΦ Accept公式包含每个表格单元格的固定大小块,因此它们的大小为O ( n 2 k )。因此Φ 的总大小为O ( n 2 k )。这个估计足以满足我们的目的,因为它表明公式Φ的大小是关于n 的多项式。如果我们的公式更大,则约简将没有机会在多项式时间内生成它。 (事实上​​,我们的估计偏差了O (log n ) 因子,因为每个变量的索引范围从 1 到n k,所以我们可能需要O (log n ) 符号来存储它们,但这个额外因子不会改变整个公式具有关于n 的多项式长度。)

We estimate the size of each part of Φ . The formula Φ cell contains a fixed-length fragment for each tableau cell, so its size is O ( n 2 k ). The formula Φ start contains a fixed-size fragment for each cell in the top row, so its size is O ( n k ). The formulas Φ move and Φ accept contain fixed-size fragments for each tableau cell, so their size is O ( n 2 k ). Hence the total size of Φ is O ( n 2 k ). This estimate is sufficient for our purposes, since it shows that the size of the formula Φ is polynomial in n . If our formula were larger, the reduction would not have a chance to generate it in polynomial time. (In fact, our estimate is underestimated by a factor of O (log n ) since each variable has indices ranging from 1 to n k , so we may need O (log n ) symbols to write it down, but this extra factor does not change the fact that the overall formula has polynomial length in n .)

看到我们可以在多项式时间内生成公式,我们可以看到它具有非常可重复的结构。公式的每个元素都是由许多几乎相同的片段构建而成,它们的不同之处仅在于以简单方式更改的索引。因此,我们可以轻松地提供一个约简,以便在多项式时间内为输入词w生成公式Φ 。

To see that we can generate the formula in polynomial time, we can see that it has a very repetitive structure. Each element of the formula is built from many almost identical fragments that differ only in indices that change in a simple way. Thus, we can easily give a reduction that will generate the formula Φ in polynomial time for an input word w .

通过证明SAT问题是 NP 完备问题,我们从而完成了库克-莱文定理的证明。证明其他语言的NP完备性一般不需要这么长的证明。相反,我们可以通过指定一种我们已经知道是 NP 完备的语言的多项式约简来证明它们是 NP 完备的。我们可以利用SAT来达到这个目的;然而,使用3SAT通常更容易,它是我们在第 302 页定义的SAT问题的变体。回想一下, 3SAT问题中的公式采用合取范式 (CNF),并且每个子句中有三个文字。首先,我们需要证明3SAT问题本身是 NP 完备的。我们将把它作为定理 7.37 的推论来展示。

We have thus completed the proof of the Cook–Levin theorem, showing that the SAT problem is NP-complete. Proving the NP-completeness of other languages ​​does not generally require such a long proof. Instead, one can prove their NP-completeness by showing a polynomial reduction from a language that we already know to be NP-complete. We can use SAT for this purpose ; however, it is usually easier to use 3SAT , a variant of the SAT problem that we defined on page 302. Recall that the formulas in the 3SAT problem are in conjunctive normal form (CNF) and have three literals in each clause. First, we need to show that the 3SAT problem itself is NP-complete. We show this as a corollary of Theorem 7.37.

应用 7.42

Motion 7.42

3SAT问题是 NP 完备问题。

The 3SAT problem is NP-complete.

证明 问题3SAT显然属于NP类,所以我们只需要证明所有属于NP类的语言在多项式时间内都归约到3SAT即可。我们可以通过证明可以将SAT问题多项式简化为3SAT来做到这一点。相反,我们修改定理 7.37 的证明,直接以每个子句三个文字的合取范式构造公式。

Proof The 3SAT problemis of course in NP, so we only need to prove that all languages ​​in NP reduce to 3SAT in polynomial time. We could do this by showing that it is possible to polynomial-time reduce SAT to 3SAT . Instead, we modify the proof of Theorem 7.37 to directly construct a formula in conjunctive normal form with three literals for each clause.

定理 7.37 创建的公式的形式已经非常接近合取范式。公式Φ cell是许多较小公式的合取,每个公式都包含更小的表达式的替代项,因此Φ cell是 CNF 的形式。公式Φ start是变量的合取。将每个变量视为大小为 1 的子句,我们看到Φ start也是 CNF 的形式。Φ接受公式是一个变量析取,因此是一个子句。Φ移动公式是唯一一个还没有合取范式的公式,但我们可以轻松地将其转换为如下形式。

Theorem 7.37 produces a formula that is already in a form very close to conjunctive normal form. The formula Φ cell is a conjunction of many smaller formulas, each of which contains a disjunction of smaller expressions, so Φ cell is in CNF form. The formula Φ start is a conjunction of variables. Treating each of these variables as a clause of size 1, we see that Φ start is also in CNF form. The formula Φ accept is a disjunction of variables and therefore a single clause. The formula Φ move is the only one that is not yet in conjunctive normal form, but we can easily transform it into conjunctive normal form as follows.

回想一下,Φ move是子表达式的合取,每个子表达式都是描述所有可能的有效窗口的合取的析取。第 0 章中描述的交换律表明,我们可以用与其等价的析取合取来代替合取的析取。这个动作可以显着增加每个子表达式的大小,但是整个Φ移动公式的大小只会增加一个常数因子,因为每个子表达式的大小仅取决于机器N ,而不取决于中的字长。结果是一个合取范式的公式。

Recall that Φ move is a conjunction of subexpressions, each of which is a disjunction of conjunctions describing all possible valid windows. The commutative laws described in Chapter 0 say that we can replace the disjunction of a conjunction by its equivalent conjunction of disjunctions. This can significantly increase the size of each subexpression, but the size of the entire formula Φ move increases only by a constant factor, since the size of each subexpression depends only on the machine N , not on the length of the word w . The result is a formula in conjunctive normal form.

现在我们已将公式写为 CNF,我们可以将其转换为每个子句中包含三个文字的公式。在当前包含一两个文字的每个子句中,我们复制其中一个,直到总数达到三个。我们将任何包含三个以上文字的子句拆分为多个子句,添加辅助变量来维持原始公式的可满足性或不可满足性。

Now that we have written the formula in CNF form, we can transform it into one that contains three literals in each clause. In each clause that currently contains one or two literals, we duplicate one of them, until the total number of literals is three. We split each clause that contains more than three literals into multiple clauses, adding auxiliary variables to preserve the satisfiability or unsatisfiability of the original formula.

例如,我们可以将子句 ( a 1 a 2 a 3 a 4 )替换为由两个子句组成的表达式 ( a 1 a 2 z ) ( z a 3 ),其中a是文字∨ a 4 ),其中z是一个新变量。如果变量a的某些估值满足原始子句,那么我们可以找到z的赋值,使得两个新子句也满足,反之亦然。一般来说,如果一个子句包含l 个文字,

For example, the clause ( a 1 a 2 a 3 a 4 ), where a and are literals, can be replaced by an expression consisting of two clauses ( a 1 a 2 z ) ( z a 3 a 4 ), where z is a new variable. If some valuation of variables a and satisfies the original clause, then we can find an assignment for z such that the two new clauses also satisfy it, and vice versa. In general, if the clause contains l literals,

( a 1 a 2 a 3 a l ),

( a 1 a 2 a 3 a l ),

那么我们可以用l − 2 个子句替换它

we can replace it with l − 2 clauses

( a 1 a 2 z 1 ) ( z 1 a 3 z 2 ) ( z 2 a 4 z 3 ) ( z l −3 a l −1 a l )。

( a 1 a 2 z 1 ) ( z 1 a 3 z 2 ) ( z 2 a 4 z 3 ) ( z l −3 a l −1 a l ).

当且仅当原始公式可满足时,我们可以轻松地检查新公式是否可满足,从而完成证明。

We can easily check that the new formula is satisfiable if and only if the original formula is satisfiable, which completes the proof.

7.5

进一步的NP完备问题

7.5

Further NP-complete problems

NP完备性现象很常见。 NP完备问题出现在许多领域。由于尚未充分理解的原因,大多数自然发生的 NP 问题要么属于 P 类,要么属于 NP 完备问题。如果我们正在寻找一个新的 NP 问题的多项式时间算法,那么值得花一些时间尝试证明它是 NP 完备的,因为这样我们就可以避免浪费精力去寻找不存在的算法。

The phenomenon of NP-completeness is widespread. NP-complete problems occur in many domains. For reasons that are not yet well understood, most naturally occurring NP problems are either P or NP-complete. If we are looking for a polynomial-time algorithm for a new NP problem, it is worth spending some time trying to prove that it is NP-complete, since that way we can save ourselves from wasting effort on finding an algorithm that does not exist.

在本节中,我们将提出几个进一步的定理,表明某些语言是 NP 完备的。这些示例将演示此类证明中使用的技术。一般策略是展示从3SAT到所研究语言的多项式约简,尽管有时从另一种 NP 完备语言的约简会更方便。

In this section we present several more theorems showing that certain languages ​​are NP-complete. These examples demonstrate the techniques used in proofs of this kind. The general strategy is to show a polynomial reduction from 3SAT to the language under consideration, although sometimes a reduction from another NP-complete language will be more convenient.

当为某种语言构建3SAT多项式约简时,我们将寻找该语言中可以模拟逻辑公式中的变量和子句的结构。此类结构有时称为小工具。例如,在定理 7.32 所示的从3SATCLIQUE 的约简中,顶点模拟变量,顶点三元组模拟子句。单个顶点可能是也可能不是团的成员,对应于可以分配 TRUE 或 FALSE 值的变量。每个子句必须包含一个指定为 TRUE 值的文字。因此,每个三元组必须包含一个属于某个团的顶点(以实现该团的预期大小)。定理 7.32 的以下推论表明CLIQUE问题是 NP 完备问题。

In constructing the polynomial reduction of 3SAT to a language, we will look for structures in that language that can simulate variables and clauses in logical formulas. Such structures are sometimes called gadgets . For example, in the reduction from 3SAT to CLIQUE , given in Theorem 7.32, vertices simulate variables, and triplets of vertices simulate clauses. A single vertex may or may not be a member of a clique, corresponding to a variable that can be assigned the value TRUE or FALSE. Each clause must contain a literal that is assigned the value TRUE. Correspondingly, each triple must contain a vertex that is a member of the clique (in order to achieve the intended size of the clique). The following corollary of Theorem 7.32 states that the CLIQUE problem is NP-complete.

应用 7.43

Motion 7.43

CLIQUE问题是 NP 完备问题。

The CLIQUE problem is NP-complete.

根尖覆盖问题

Vertex Coverage Problem

如果G是无向图,则G 的顶点覆盖 是顶点的子集,使得G中的每条边都到达这些顶点之一。顶点覆盖问题是判断一个图是否具有给定大小的顶点覆盖:

If G is an undirected graph, then a vertex cover of G is a subset of its vertices such that every edge in G reaches one of those vertices. The vertex cover problem is to determine whether a graph has a vertex cover of a specified size:

VERTEX-COVER = { G , k G是一个无向图,其顶点覆盖大小为k }。

VERTEX-COVER = { G , k : G is an undirected graph that has a vertex cover of size k }.

定理7.44

Theorem 7.44

VERTEX-COVER问题是 NP 完备问题。

The VERTEX-COVER problem is NP-complete.

证明的概念 为了证明VERTEX-COVER问题是 NP 完备的,我们需要证明它属于 NP 类,并且该类中的所有问题在多项式时间内都归结为该问题。第一部分很简单。该图的证书是大小为k的顶点覆盖。为了演示第二部分,我们将证明 3SAT 问题可以多项式简化为VERTEX-COVER。该约简将 3CNF 公式Φ转换为图G和数字k,使得Φ当且仅当G具有k 个顶点的顶点覆盖时可满足我们在不知道公式Φ是否可满足的情况下执行此变换。因此,图G模拟了公式Φ。该图包含模仿公式的变量和子句的小工具。设计这些小工具需要一些独创性。

Concept of the proof To show that the VERTEX-COVER problem is NP-complete, we need to show that it is in the class NP and that all problems in this class reduce to it in polynomial time. The first part is straightforward. The certificate for the graph is a vertex cover of size k . To prove the second part, we show that the 3SAT problem is polynomial reducible to VERTEX-COVER . The reduction transforms the 3CNF formula Φ into a graph G and a number k in such a way that Φ is satisfiable if and only if G has a vertex cover of k vertices. We perform this transformation without knowing whether the formula Φ is satisfiable. As a result, the graph G simulates the formula Φ . The graph contains gadgets that mimic the variables and clauses of the formula. Designing these gadgets requires some ingenuity.

为了获得变量的小工具,我们需要在图G中寻找可以以两种可能的方式参与顶点覆盖的结构,对应于变量的两种可能的赋值。可变小工具包含由边连接的两个顶点。这种结构之所以有效,是因为这些顶点之一必须属于顶点覆盖范围。我们自由地为这些顶点分配TRUE和FALSE值。

To obtain a gadget for a variable, we need to search the graph G for a structure that can participate in the vertex cover in two possible ways, corresponding to two possible assignments of values ​​to the variable. The gadget for the variable contains two vertices connected by an edge. This structure works because one of these vertices must belong to the vertex cover. We assign arbitrary values ​​TRUE and FALSE to these vertices.

创建子句小工具时,我们将寻找一种结构,该结构将导致顶点覆盖范围包含来自与该子句中至少一个 TRUE 文字相对应的变量小工具的顶点。该小工具包含三个顶点和附加边,因此任何顶点覆盖范围至少包含这些顶点中的两个,也可能包含全部三个。当其中一条边被变量小工具中的顶点覆盖时,将需要两个顶点,这模拟为该变量选择一个满足我们的子句的值。否则,需要三个顶点。最后,我们选择k,使得我们正在寻找的顶点覆盖范围包含每个变量 gadget 的一个顶点和每个子句 gadget 的两个顶点。

When creating a clause gadget, we will look for a structure that will cause the vertex cover to contain vertices from the variable gadgets that correspond to at least one literal that is TRUE in the clause. The gadget contains three vertices and additional edges, so that any vertex cover will contain at least two of these vertices, and possibly all three. Two vertices will be required if one of the edges is covered by a vertex from the variable gadget, simulating choosing a value of that variable that satisfies our clause. Otherwise, three vertices are required. Finally, we choose k so that the vertex cover we are looking for contains one vertex for each variable gadget and two vertices for each clause gadget.

证明我们现在将3SAT 问题多项式约简的细节呈现给VERTEX-COVER。这种简化将逻辑公式Φ转换为图G和数字k。属于Φ的每个变量x ,我们创建一条连接两个顶点的边。我们用xx标记这个小工具的顶点。将 TRUE 替换x对应于选择带有标签x的顶点进行顶点覆盖,而 FALSE 值对应于选择带有标签x 的顶点。

Proof We now present the details of the polynomial reduction of the 3SAT problem to VERTEX-COVER . This reduction transforms a Boolean formula Φ into a graph G and a number k . For each variable x in Φ we create an edge connecting two vertices. We label the vertices of this gadget x and x . Substituting TRUE for x corresponds to selecting the vertex with label x for the vertex cover, while FALSE corresponds to selecting the vertex with label x .

子句小工具有点复杂。子句的每个小工具都是由该子句的三个文字描述的顶点三元组。这三个顶点相互连接,并连接到具有相同标签的变量顶点。因此,图G中将出现的节点总数为 2 m + 3 l,其中m是公式Φ中的变量数量,l是子句数量。令km + 2l

Clause gadgets are a bit more complex. Each clause gadget is a triplet of vertices described by three literals of the clause. These three vertices are connected to each other and to the nodes of variables that have identical labels. Thus, the total number of nodes that will appear in the graph G is 2m + 3l , where m is the number of variables in the formula Φ and l is the number of clauses. Let k equal m + 2l .

例如,如果Φ = ( x 1 x 1 x 2 ) ( x 1 x 2 x 2 ) ( x 1 x 2 x 2 ),则约简将创建对G , k由公式Φ 可知,其中k = 8,G 的形式如下图所示。

For example, if Φ = ( x 1 x 1 x 2 ) ( x 1 x 2 x 2 ) ( x 1 x 2 x 2 ), then the reduction will produce from the formula Φ a pair G , k , where k = 8 and G has the form shown in the figure below.

7.45

通过公式Φ = ( x 1 x 1 x 2 ) ( x 1 x 2 x 2 ) ( x 1 x 2 x 2 )约简创建的图形

Figure 7.45

The graph generated by reduction for the formula Φ = ( x 1 x 1 x 2 ) ( x 1 x 2 x 2 ) ( x 1 x 2 x 2 )

为了证明这种简化是正确的,我们需要证明当且仅当G具有大小为k的顶点覆盖时,公式Φ是可满足的。我们将从履行估值开始。首先,我们将变量 gadget 中对应于 TRUE 文字的顶点放入顶点覆盖范围中。然后,我们从每个子句中选择一个 TRUE 文字,并将每个子句小工具中的剩余两个顶点附加到顶点覆盖范围。这样,我们就选择了k个顶点。它们覆盖了所有边,因为可变小部件中的每条边显然都被覆盖了,子句小部件中的所有边三元组也都被覆盖了,并且连接可变小部件和子句小部件的所有边都被覆盖了。因此,图G具有大小为k的顶点覆盖。

To prove that this reduction is correct, we need to show that the formula Φ is satisfiable if and only if G has a vertex cover of size k . We start with the satisfiable valuation. First, we place in the vertex cover those vertices from the variable gadgets that correspond to literals with TRUE values. Then we select one TRUE literal from each clause and append to the vertex cover the two remaining vertices from each clause gadget. In this way, we have selected k vertices. They cover all edges, since every edge in the variable gadgets is obviously covered, all triplets of edges in the clause gadgets are also covered, and all edges connecting the variable gadgets to the clause gadgets are covered. Thus, G has a vertex cover of size k .

现在我们假设图G具有大小为k的顶点覆盖,并且我们将通过构建可满足的评估来证明公式Φ是可满足的。顶点覆盖范围必须包括每个变量小工具中的一个顶点和每个子句小工具中的两个顶点,以覆盖这些小工具中的所有边。这耗尽了可用顶点的数量,因此我们无法选择任何其他顶点。我们选择属于顶点覆盖范围的那些可变小工具顶点,并将 TRUE 分配给它们相应的文字。此分配满足公式Φ,因为将变量 gadget 连接到给定子句的 gadget 的三个边中的每一个都被覆盖,并且子句 gadget 中只有两个顶点属于覆盖范围。因此,其中一条边必须被变量 gadget 的顶点覆盖,因此该赋值满足我们的子句。

We now assume that the graph G has a vertex cover of size k and show that the formula Φ is satisfiable by constructing a satisfying valuation. The vertex cover must contain one vertex from each variable gadget and two vertices from each clause gadget to cover all edges in these gadgets. This exhausts the number of available vertices, so we cannot select any more. We select the vertices of the variable gadgets that belong to the vertex cover and assign TRUE to their corresponding literals. This assignment satisfies the formula Φ , since each of the three edges connecting the variable gadgets to the gadget of the clause is covered, and only two vertices from the clause gadget belong to the cover. Therefore, one of the edges must be covered by a vertex from the variable gadget, so this assignment satisfies our clause.

汉密尔顿路径问题

Hamilton's Path Problem

回想一下,哈密顿路径问题是检查图是否包含从顶点st的路径,并且该路径恰好经过每个顶点一次。

Recall that the Hamiltonian path problem is to test whether a graph contains a path from vertex s to t that passes through each vertex exactly once.

定理7.46

Theorem 7.46

HAMPATH问题是 NP 完备问题。

The HAMPATH problem is NP-complete.

证明的概念 在7.3节中我们证明了HAMPATH问题属于NP类。为了证明此类中的每个问题都可以在多项式时间内简化为HAMPATH,我们将证明3SAT可以在多项式时间内简化为HAMPATH。我们将展示一种将 3CNF 公式转换为图形的方法,其中哈密顿路径对应于满足这些公式的值。这些图表将包含模拟变量和子句的小工具。变量gadget将是一个菱形结构,可以通过两种方式之一遍历,对应于两个不同的逻辑值分配。该子句的小工具将是顶点。确保路径经过每个子句小工具满足每个子句在令人满意的评估中得到满足的要求。

Concept of Proof In Section 7.3 we showed that the HAMPATH problem belongs to the class NP. To show that every problem in this class can be reduced in polynomial time to HAMPATH , we show that 3SAT is polynomial-time reducible to HAMPATH . We show a way to transform 3CNF formulas into graphs in which Hamiltonian paths correspond to the satisfying valuations for these formulas. The graphs will contain gadgets that mimic variables and clauses. A variable gadget will be a diamond-shaped structure that can be traversed in one of two ways, corresponding to two different assignments of truth values. A clause gadget will be a vertex. Ensuring that a path passes through every clause gadget corresponds to the requirement that every clause is satisfied in the satisfying valuation.

证明 我们之前已经证明了HAMPATH问题属于 NP 类,因此我们需要证明3SAT P HAMPATH。对于 3CNF 形式的每个公式Φ,我们将展示如何构造一个包含两个不同顶点st的有向图G,其中当且仅当公式Φ可满足时,这些顶点之间存在哈密顿路径。

Proof We have shown earlier that the HAMPATH problem is in NP, so it remains to show that 3SAT P HAMPATH . For any3CNF formula Φ , we show how to construct a directed graph G containing two distinguished vertices s and t , such that there exists a Hamiltonian path between these vertices if and only if the formula Φ is satisfiable.

我们将从包含k 个子句的 3CNF 公式开始构建,

We will start the construction with a 3CNF formula containing k clauses,

Φ = ( a 1 b 1 c 1 ) ( a 2 b 2 c 2 ) ( a k b k c k ),

Φ = ( a 1 b 1 c 1 ) ( a 2 b 2 c 2 ) ( a k b k c k ),

其中abc都是x ix i形式的文字。令x 1 , …, x l为公式Φ的所有l 个变量。

where all a , b , and c are literals of the form x i or x i . Let x 1 , …, x l be all l variables of the formula Φ .

现在我们将展示如何将公式Φ转换为图G。构建的图G将包含表示Φ中出现的变量和子句的各种片段。

We now show how to transform the formula Φ into a graph G . The constructed graph G will contain various fragments representing variables and clauses appearing in Φ .

我们将每个变量x i表示为一个菱形结构,在对角线上包含一系列水平顶点,如下图所示。稍后我们将确定出现在这条对角线上的顶点数量。

We will represent each variable x i as a diamond-shaped structure containing a horizontal sequence of vertices on the diagonal, as shown in the figure below. Later we will determine the number of vertices that appear on this diagonal.

7.47

将变量x i表示为图中的菱形结构

Figure 7.47

Representation of the variable x i as a diamond-shaped structure in the graph

我们将Φ公式的每个子句表示为单个顶点。

We will represent each clause of the formula Φ as a single vertex.

7.48

将子句c j表示为顶点

Figure 7.48

Representation of the clause c j as a vertex

图 7.49 显示了图G的一般结构。除了表示变量和包含变量的子句之间的关系的边之外,所有G元素及其相互关系在这里都是可见的。

Figure 7.49 shows the general structure of the graph G . It shows all the elements of G and their mutual relations, except for the edges representing dependencies between variables and the clauses that contain them.

7.49 G

图的一般结构

Figure 7.49

The general structure of the graph G

然后,我们将向您展示如何将代表变量的菱形与代表子句的顶点连接起来。每个菱形都包含一条水平对角线,该对角线由通过双向延伸的边连接的顶点组成。不计算菱形的两个极端顶点,这条对角线包含 3k +1 个顶点。这些顶点被分组为相邻对,每个子句对应一个顶点,它们之间还有额外的分隔顶点,如下图所示。

Next, we show how to connect the rhombuses representing variables to the vertices representing clauses. Each rhombus contains a horizontal diagonal consisting of vertices connected by edges going in both directions. Not counting the two outermost vertices of the rhombus, this diagonal contains 3k +1 vertices. These vertices are grouped into adjacent pairs, one for each clause, with additional splitting vertices between them, as in the figure below.

7.50

菱形水平对角线上的顶点

Figure 7.50

Vertices on the horizontal diagonal of a rhombus

如果变量x i出现在子句c j中,则我们将以下两条边从第 i 个菱形的第 j对添加到第 j 个子句的顶点。

If variable x i appears in clause c j , then we add the following two edges from the j -th pair of i -th rhombus to the vertex of the j -th clause.

7.51当子句c j包含变量x i

时,图中放置的附加边

Figure 7.51

Additional edges inserted into the graph when the c j clause contains a variable x i

如果文字x i出现在子句c j中,我们将第 i 个菱形的第 j对中的两条边添加到第 j 个子句的顶点,如图 7.52 所示。

If clause c j contains a literal x i , then we add the two edges from the j -th pair of i -th rhombuses to the vertex of the j -th clause, as in Figure 7.52.

添加与每个子句中每次出现的文字x ix i相对应的所有边后,图G的构造就完成了。为了证明这种构造有效,我们将证明如果公式Φ可满足,则图中存在从顶点st 的哈密顿路径。反之,如果存在这样的路径,我们将证明公式Φ是可满足的。

Once we have added all the edges corresponding to each occurrence of the literal x i or x i in each clause, the construction of the graph G is complete. To show that this construction works, we show that if the formula Φ is satisfiable, then there exists a Hamiltonian path in the graph from vertex s to t . Conversely, if such a path exists, then we show that the formula Φ is satisfiable.

7.52当c j包含文字x i

时图中放置的附加边

Figure 7.52

Additional edges inserted into the graph when c j contains a literal x i

让我们假设公式Φ是可满足的。为了证明从st的哈密顿路径的存在,我们首先忽略子句顶点。该路径从顶点s开始,依次经过每个菱形,并在顶点t结束。要访问菱形对角线上的顶点,路径要么从左到右穿过它们,要么从右到左穿过它们。这些转变的方向取决于满足公式Φ的评估。如果为变量x i指定值 TRUE,则路径从左到右穿过适当的菱形。如果分配的值为 FALSE,则路径从右到左穿过菱形。下图显示了两种可能性。

Assume that the formula Φ is satisfiable. To show the existence of a Hamiltonian path from s to t , we first omit the vertices of the clauses. The path starts at vertex s , traverses each rhombus in turn, and ends at vertex t . To visit the vertices on the diagonals of the rhombus, the path either traverses them from left to right or from right to left. The directions of these traversals depend on the evaluation that satisfies the formula Φ . If the variable x i is assigned the value TRUE, then the path traverses the corresponding rhombus from left to right. If the assigned value is FALSE, then the path traverses the corresponding rhombus from right to left. Both possibilities are shown in the figure below.

7.53

根据满足公式的估值通过菱形结构左右移动

Figure 7.53

Right and left transitions through the rhombus structure depending on the evaluation that satisfies the formula

到目前为止,我们的路径覆盖了图G除子句顶点之外的所有顶点。我们可以通过在菱形对角线上的顶点添加“旁路”(腿)来轻松连接它们。在每个子句中,我们选择在令人满意的评估中评估为 TRUE 的文字之一。

So far, our path covers all vertices of G except the clause vertices. We can easily join them by adding “bypasses” (branches) at the vertices on the rhombus diagonals. In each clause, we choose one of the literals that evaluates to TRUE in the satisfying evaluation.

如果我们在c j子句中选择x i ,我们可以在第 i 个菱形的第 j对中执行解决方法。这是可行的,因为x i必须为 TRUE,因此路径从左到右经过相应菱形的对角线。这确保了到顶点cj的边的顺序正确,允许遍历它并返回。

If we choose x i in clause c j , then we can perform a bypass in the j -th pair of the i -th rhombus. This is feasible because x i must be TRUE, so the path traverses the corresponding rhombus diagonal from left to right. This ensures that the edges to vertex c j are in the correct order, allowing us to traverse to it and back.

类似地,如果我们在c j子句中选择x i ,我们可以在第i 个菱形的第 j对中执行旁路,因为x i必须为 FALSE,因此路径从右向左遍历相应的菱形。同样这确保了通往顶点j和返回的边的方向正确。 (请注意,子句中每个计算结果为 TRUE 的文字都会创建一个解决方法来访问该子句的顶部。因此,如果子句中的多个文字计算结果为 TRUE,我们仅选择一种解决方法。)这样,我们就有了建立了哈密顿路径。

Similarly, if we choose x i in clause c j , then we can perform a bypass in the j -th pair of the i -th diamonds, since x i must evaluate to FALSE, so the path traverses the corresponding diamond from right to left. Again, this ensures that the edges leading to vertex c j and back are in the correct direction. (Note that each TRUE literal in the clause creates a bypass possibility to visit the vertex of that clause. As a result, if multiple literals in the clause evaluate to TRUE, we choose only one bypass.) In this way, we have constructed a Hamiltonian path.

为了证明相反的方法,我们将证明如果图G包含从st的哈密顿路径,那么公式Φ就有一个令人满意的评估。如果这个哈密顿路径是普通的——也就是说,除了绕过子句顶点之外,它按照从最高到最低的顺序穿过菱形,那么我们可以很容易地获得一个可满足的分配。如果路径从左到右穿过菱形,我们将值 TRUE 分配给适当的变量。如果它从右到左,我们分配 FALSE。由于每个子句顶点都出现在路径上,通过分析哪个旁路路径访问该顶点,我们可以读取给定子句的哪些文字具有 TRUE 值。

To prove the other way, we show that if the graph G contains a Hamiltonian path from s to t , then there is a satisfying valuation for the formula Φ . If this Hamiltonian path is ordinary —that is, it traverses the rhombuses in order from highest to lowest except for bypasses to clause vertices—then we can easily obtain a satisfying assignment. If the path traverses the rhombus from left to right, we assign the appropriate variable the value TRUE. If it traverses from right to left, we assign FALSE. Since each clause vertex appears on the path, by analyzing which bypass the path visits this vertex, we can read off which of the literals of the given clause has the value TRUE.

仍有待证明的是,图G中的哈密顿路径必须是“普通的”。仅当路径从一个菱形进入子句但返回到另一个菱形时,才会保留这种“正常性”,如下图所示。

It remains to show that a Hamiltonian path in a graph G must be "ordinary". This "ordinariness" would not hold only if the path entered the clause from one rhombus but returned to another, as in the figure below.

7.54

这种情况不能发生

Figure 7.54

This situation cannot occur

该路径从顶点a 1c,但不是返回到同一个菱形中的a 2,而是到达另一个菱形中的顶点b 2 。如果发生这种情况,那么23必须是分隔对角线上的对的顶点如果a 2是分裂顶点,则进入它的唯一边将来自顶点a 1a 3。如果3分离顶点,则12将属于同一对,因此进入2 的唯一将来自a 1a 3以及来自 c。在这两种情况下,路径都不能包含顶点a 2。该路径不能输入2c1 ,因为从这些顶点它通向其他地方。该路径也不能从顶点 a 3通向 2 ,因为 3 是 2指向唯一可用顶点因此路径必须通过a 3离开a 2。所以我们看到汉密尔顿的道路一定是“平凡的”。

A path goes from vertex a 1 to c , but instead of returning to a 2 in the same rhombus, it goes to vertex b 2 in a different rhombus. If this were to happen, then either a 2 or a 3 would have to be the vertex that divides the pairs on the diagonal. If a 2 were the dividing vertex, then the only edges entering it would come from vertices a 1 and a 3 . If a 3 were the dividing vertex, then a 1 and a 2 would be members of the same pair, so the only edges entering a 2 would be from a 1 , a 3 , and  c . In either case, the path could not include vertex a 2 . The path cannot enter a 2 from either c or a 1 , because from these vertices it leads somewhere else. Nor can the path lead to a 2 from vertex a 3 , since a 3 is the only accessible vertex pointed to by a 2 , so the path must leave a 2 through a 3 . We see, therefore, that the Hamiltonian path must be "ordinary".

这种约简显然是在多项式时间内进行的,从而完成了证明。

This reduction obviously works in polynomial time, which completes the proof.

作为下一个示例,我们考虑汉密尔顿路径问题的无向版本UHAMPATH。为了证明UHAMPATH问题是 NP 完备问题,我们展示了该问题的有向图版本的多项式约简。

As a next example, we consider the undirected version of the Hamiltonian path problem, UHAMPATH . To show that the UHAMPATH problem is NP-complete, we show a polynomial reduction from the version of the problem for directed graphs.

定理7.55

Theorem 7.55

UHAMPATH问题是 NP 完备问题。

The UHAMPATH problem is NP-complete.

证明 作为输入,我们的归约接收一个具有可区分顶点st的有向图G,基于该有向图G'构建具有可区分顶点s't'的无向图 G' 。图G具有从st的哈密顿路径当且仅当G'具有从s't'的哈密顿路径。如下图G' 。

Proof Our reduction is given as input a directed graph G with distinguished vertices s and t , from which it constructs an undirected graph G' with distinguished vertices s' and t' . The graph G has a Hamiltonian path from s to t if and only if G' has a Hamiltonian path from s' to t' . We will describe the graph G' as follows.

我们将图G除顶点st之外的每个顶点替换为三个顶点u inu midu out。图G中的顶点st在图G'中被替换为顶点s out = s't in = t'。在图G'中,我们创建两种类型的边。第一个是连接u midu inu out 的边。第二个是连接u outv in 的边(如果图G中存在从uv 的边)。这样就完成了图G'的构造。

Each vertex u of graph G except vertices s and t is replaced in graph G' by a triplet of vertices u in , u mid , and u out . Vertices s and t from graph G are replaced in graph G' by vertices s out = s' and t in = t' . In graph G' we create edges of two types. The first are edges connecting u mid with u in and u out . The second are edges connecting u out with v in , if in graph G there is an edge leading from u to v . This completes the construction of graph G' .

我们将证明这种构造是正确的,即我们将证明图G具有从顶点st 的哈密顿路径当且仅当图 G' 具有从顶点s outt in 的哈密顿路径。为了在第一个方向上显示这一点,只需注意图G中的哈密顿路径P

We will prove that this construction is correct, i.e. we will show that the graph G contains a Hamiltonian path from vertex s to t if and only if the graph G' has a Hamiltonian path from vertex s out to t in . To show this in the first direction, it suffices to note that for a Hamiltonian path P in the graph G ,

s , u 1 , u 2 , …, u k , t ,

s , u 1 , u 2 , …, u k , t ,

对应于图G'中的哈密顿路径P' ,

corresponds to the Hamiltonian path P' in the graph G',

su输入1u mid 1u1、、...、t输入

s out , u in 1 , u mid 1 , u out 1 , , …, t in .

为了证明相反方向的证明,我们证明图G'中从顶点s outt in 的任何哈密顿路径必须从一个三元组通向下一个三元组,除了开始和结束之外,就像刚刚描述的路径P ' 一样。这足以完成证明,因为任何此类路径在图G中都有对应的哈密顿路径。我们将通过沿着从顶点s out开始的路径来证明这一点。请注意,对于某些i,路径的下一个顶点必须是u in i,因为只有这样的顶点才有将它们连接到s out 的边。下一个顶点必须是u mid i,因为我们没有其他方法可以将该顶点包含在汉密尔顿路径中。顶点u mid i后面跟着u out i,因为它是u mid i连接到的唯一其他顶点。对于某些j ,下一个顶点必须是u in j,因为没有其他可用顶点连接到u out i。然后对后续三元组重复该论证,直到到达中的顶点t

To show the proof in the opposite direction, we show that any Hamiltonian path in the graph G' from vertex s out to t in must go from one triplet to the next except the start and the end, just as the path P ' just described. This is enough to complete the proof, since any path of this kind has a corresponding Hamiltonian path in the graph G . We prove this by following the path from vertex s out . Note that the next vertex of the path must be u in i for some i , since only such vertices have edges connecting them to s out . The next vertex must be u mid i , since there is no other way to include this vertex in the Hamiltonian path. Vertex u mid i is followed by u out i , since this is the only other vertex to which u mid i is connected. The next vertex must be u in j for some j , since no other available vertex is connected to u out i . This argument is then repeated for subsequent triples until we reach vertex t in .

子集和问题

Subset sum problem

让我们回到第 297 页定义的SUBSET-SUM问题。在这个问题中,我们得到一组数字x 1 , ..., x k和一个目标值t,并要求我们确定该组是否包含总和为t 的子集。现在我们将证明这个问题是 NP 完备问题。

Let us return to the SUBSET-SUM problem defined on page 297. In this problem, we are given a set of numbers x 1 , …, x k and a target value t , and we are to determine whether this set contains a subset that sums to t . We now show that this problem is NP-complete.

定理7.56

Theorem 7.56

SUBSET-SUM问题是 NP 完备问题。

The SUBSET-SUM problem is NP-complete.

证明的概念 我们已经在定理 7.25 中证明了SUBSET-SUM问题属于 NP 类。我们现在将证明 NP 类的所有语言都可以在多项式时间内简化为SUBSET-SUM问题,从而将 NP 完备3SAT问题简化为 SUBSET-SUM 问题。基于 3CNF Φ公式,我们将构造一个SUBSET-SUM问题当且仅当Φ公式可满足总和等于目标值t的子集。我们将这个子集称为 T。

Concept of the Proof We have already shown in Theorem 7.25 that the SUBSET-SUM problem belongs to the class NP. We now show that all languages ​​in the class NP reduce in polynomial time to the SUBSET-SUM problem , reducing to it the NP-complete problem 3SAT . From the 3CNF formula Φ we construct an instance of the SUBSET-SUM problemthat contains a subset that sums to a target value t if and only if the formula Φ is satisfiable. We will call this subset T.

为了获得这种减少,我们将在SUBSET-SUM问题中寻找表示变量和子句的结构。我们将构建的SUBSET-SUM问题的示例将包含以十进制书写的大量数字。我们将用数字对来表示变量,并用这些数字的十进制表示中的特定位置来表示子句。

To achieve this reduction, we will find structures in the SUBSET-SUM problem that represent variables and clauses. The instance of the SUBSET-SUM problem that we will construct will contain large numbers, written in the decimal system. We will represent variables by pairs of numbers, and clauses by specific positions in the decimal representation of those numbers.

让变量x i对应于两个数字y iz i。我们将证明,对于每个iy iz i必须属于 T,这将在令人满意的评估中创建变量x i的逻辑值的编码。

Let the variable x i correspond to two numbers y i and z i . We will show that for each i either y i or z i must belong to T, which will form an encoding of the logical value of the variable x i in the satisfying valuation.

每个子句项将在目标总和t中包含特定值,这对子集T提出了特定要求。我们将证明这一要求与相应子句中的要求相同 - 即该子句中的文字之一必须被赋予值 TRUE。

Each entry in the clause will contain a specific value in the target sum t , which imposes specific requirements on the subset of T . We will prove that this requirement is the same as that in the corresponding clause—namely, that one of the literals in the clause must evaluate to TRUE.

证明 我们已经知道SUBSET-SUM NP,所以我们只需要证明3SAT P SUBSET-SUM

Proof We already know that SUBSET-SUM NP, so we only need to show that 3SAT P SUBSET-SUM .

Φ为包含变量x 1 , …, x l和子句c 1 , …, ck逻辑公式。简化将公式Φ转换为SUBSET-SUM S, t 问题的一个实例,其中 S 的元素和数字t是图 7.57 中表的行,以正则十进制表示法读取。双线上方的行已标记

Let Φ be a Boolean formula with variables x 1 , …, x l and clauses c 1 , …, c k . Reduction transforms the formula Φ into an instance of the SUBSET-SUM problem S, t , where the elements of S and the number t are the rows of the array shown in Figure 7.57, read as ordinary decimal notation. The rows above the double line are labeled

y 1 , z 1 , y 2 , z 2 , …, y l , z lz g 1 , h 1 , g 2 , h 2 , …, g k , hk

y 1 , z 1 , y 2 , z 2 , …, y l , z l or z g 1 , h 1 , g 2 , h 2 , …, g k , h k

并形成集合 S 的元素。双线下方的线是数字t

and form elements of the set S. The line below the double line is the number t .

因此,我们看到对于公式Φ的每个变量x i z ,S 包含一对数字y iz i。这些数字的十进制表示形式有两部分,如表​​中所示。左侧由 1 后跟l0 组成。右侧每个子句包含一位数字,其中如果子句c j包含文字x i ,则c j列中的数字y i的数字等于 1 ;如果子句c j包含文字x i,则c j列中数字z i的数字等于 1。所有其他数字均为 0。

Thus, we see that S contains one pair of numbers y i , z i for each variable x i from the formula Φ . The decimal representation of these numbers has two parts, as indicated in the table. The left-hand side consists of ones followed by land zeros. The right-hand side contains one digit for each clause, where the digit of the number y i in column cj is equal to 1 if clause cj contains a literal x i ; the digit of the number z i in column cj is equal to 1 if clause cj contains a literal x i . All the other digits are equal to 0.

图中所示的表已部分填充,如示例子句c 1c 2ck所示

The table shown in the figure is partially filled, which illustrates the example clauses c 1 , c 2 and c k :

( x 1 x 2 x 3 ) ( x 2 x 3 ) ( x 3 )

( x 1 x 2 x 3 ) ( x 2 x 3 ) ( x 3 )

另外,S对于每个子句c j包含一对数字g jh j。这两个数字相等,由 1 后跟kj个零组成。

Additionally, S contains one pair of numbers g j , h j for each clause c j . These two numbers are equal and consist of a one followed by kj zeros.

最后,目标数字t(如表底行所示)由l个 1 和后跟k 个3 组成。

Finally, the target number t , shown in the bottom row of the table, consists of l ones followed by k threes.

现在我们将向您展示为什么这种设计有效。我们将证明当且仅当 S 的某个子集之和等于t时,公式Φ是可满足的。

We will now show why this construction works. We will prove that the formula Φ is satisfiable if and only if some subset of S sums to t .

让我们假设公式Φ是可满足的。我们将如下构造集合S的子集。如果赋值中变量x i为 TRUE ,我们选择y i ;如果x i被赋值为 FALSE,则选择z i 。当我们添加以这种方式选择的数字时,前l 个数字中的每一个数字都是 1,因为我们为每个i选择了y iz i。此外,最后k位数字中的每一位都是 1 到 3 之间的数字,因为满足每个子句,因此包含 1 到 3 个分配了值 TRUE 的文字。现在,我们可以另外选择足够的数字gh,使最后k位数字中的每一位都达到 3,从而达到所需的总和。

Assume that the formula Φ is satisfiable. We construct a subset of S in the following way. We choose y i if in the assignment that satisfies, the variable x i is assigned the value TRUE, and z i if x i is assigned the value FALSE. When we add up the numbers chosen in this way, we get 1 as each of the first l digits, since we have chosen either y i or z i for each i . Moreover, each of the last k digits is a digit between 1 and 3, since each clause is satisfied, and so contains from 1 to 3 literals assigned the value TRUE. We can now additionally choose enough numbers g and h to bring each of the last k digits to 3, achieving the desired sum.

7.57

3SAT问题简化为SUBSET-SUM

Figure 7.57

Reduction of the 3SAT problem to SUBSET-SUM

现在假设 S 的一个子集总和为t。通过一些观察,我们将构建一个满足公式Φ的估值。首先,属于集合S的所有数字不是零就是一。此外,描述集合S的表的每一列最多包含五个。因此,当添加 S 的任何子集的元素时,都不会发生任何转移。为了在前l列中的每一列中获得 1 ,该子集对于每个i可以包含y iz i,但不能同时包含两者。

Now suppose that there is a subset of S that sums to t . Several observations allow us to construct a valuation that satisfies the formula Φ . First, all digits of numbers belonging to S are either zero or one. Furthermore, each column of the table describing S contains at most five ones. Thus, when adding elements of any subset of S, there will never be a carry. In order to get a 1 in each of the first l columns, the subset must contain for each i either y i or z i , but not both.

我们现在可以构建令人满意的作业。如果子集包含y i,我们将值x i指定为 TRUE;否则我们给它赋值 FALSE。此分配必须满足公式Φ,因为在最后k列中的每一列中,总和始终为 3。在c j列中,使用数字g jh j 给出的总和最多为 2,因此其中至少有一个 1列必须来自某个数字y/或来自属于子集的i 。如果是y i,则x i出现在子句c j中并被赋予值 TRUE,因此满足c j 。如果是z i ,则c j子句包含x i并且我们已将x i的值赋为 FALSE,因此满足c j 。由此可见整个公式Φ都满足。

We can now construct a satisfying assignment. If the subset contains y i , we assign the value TRUE to x i ; otherwise we assign it the value FALSE. This assignment must satisfy the formula Φ , since in each of the final k columns the sum is always 3. In column cc j , the numbers g j and h j sum to at most 2, so at least one 1 in this column must come from some number y i or z i in the subset. If this is y i , then x i occurs in clause cc j and is assigned the value TRUE, so c j is satisfied. If this is z i , then x i occurs in clause cc j and is assigned the value FALSE, so c j is satisfied. It follows that the entire formula Φ is satisfied.

最后,我们需要证明减少在多项式时间内有效。数组的大小约为 ( k + l ) 2并且对于任何公式Φ都可以轻松计算每个条目。所以总时间是O ( n 2 ) 个简单步骤。

Finally, we still need to show that the reduction runs in polynomial time. The size of the array is approximately ( k + l ) 2 and each entry can be easily computed for any formula Φ . Thus, the total time is O ( n 2 ) simple steps.

练习

Exercises

7.1 对于每一项,回答表达式是真还是假。

7.1 For each point, answer whether the expression is true or false.

2n = O ( n )

a. 2 n = O ( n ).

b.n 2 = O ( n )

b. n 2 = O ( n ).

n 2 = O ( n log 2 n )

And c. n 2 = O ( n log 2 n ).

d . n log n = O ( n 2 )。

And d. n log n = O ( n 2 ).

e. 3 n = 2 O( n )

e. 3 n = 2 O( n ) .

f. 2 2 n = O (2 2 n )。

f. 2 2 n = O (2 2 n ).

7.2 对于每一项,回答表达式是真还是假。

7.2 For each point, answer whether the expression is true or false.

a. n = o (2 n )。

a. n = o (2 n ).

b. 2 n = o ( n 2 )。

b. 2 n = o ( n 2 ).

2 n = o (3 n )

And c. 2 n = o (3 n ).

d.1 = o ( n )。

And d. 1 = o ( n ).

e.n = o (log n )

e. n = o (log n ).

f. 1 = o(1/ n )。

f. 1 = o(1/ n ).

7.3 下列哪些数对互质?显示得出答案的计算。

7.3 Which of the following pairs of numbers are relatively prime? Show the calculations that led to the answer.

1274 和 10505

a. 1274 and 10505

7289和8029

b. 7289 and 8029

7.4对于单词w = baba和以下上下文无关语法G ,完成定理 7.16 的多项式时间语言识别算法中描述的表格:

7.4 Complete the table described in the polynomial-time language recognition algorithm from Theorem 7.16 for the word w = baba and the following context-free grammar G :

短线 短线

S RT

R TR |

R TR | a

T TR |

T TR | b

7.5 下面的公式可满足吗?

7.5 Is the following formula satisfiable?

( x y ) ( x y ) ( x y ) ( x y )

( x y ) ( x y ) ( x y ) ( x y )

7.6 证明类 P 对于并集、串联和补集是闭集。

7.6 Prove that the class P is closed under union, concatenation and complement.

7.7 证明NP类对于并集和串联是闭集的。

7.7 Prove that the class NP is closed under union and concatenation.

7.8CONNECTED = { G G是连通无向图}。分析第185页的算法表明该语言属于P类。

7.8 Let CONNECTED = { G : G is a connected undirected graph}. Analyze the algorithm on page 185 to show that this language belongs to the class P.

7.9无向图中的 三角形是 3 派。证明TRIANGLE P,其中TRIANGLE = { G : G包含一个三角形}。

7.9 A triangle in an undirected graph is a 3-clique. Show that TRIANGLE P, where TRIANGLE = { G : G contains a triangle}.

7.10 证明ALL DFA语言属于P类。

7.10 Prove that the ALL DFA language belongs to the class P.

7.11 在这两小节中,对所提出的算法的时间复杂度进行分析。

7.11 In both sub-items, present an analysis of the time complexity of the proposed algorithm.

a. 证明EQ DFA P。

a. Show that EQ DFA P.

b.如果A = A *, 我们称语言A由于星号操作而封闭(Kleene 闭包) 。引入多项式算法来检查 DFA 是否由于星号操作而识别封闭语言。 (请注意,EQ NFA未知为 P 类。)

b. A language A is said to be asterisk closed (Kleene closure) if A = A * . Give a polynomial-time algorithm to check whether a DFA recognizes a language asterisk closed. (Note that it is not known whether the EQ NFA belongs to the class P.)

7.12如果G的顶点可以按两个图相同的方式排序,则 图G和 H 被称为同构。令ISO = { G , H G和 H 是同构图}。证明ISO NP。

7.12 Graphs G and H are called isomorphic if the vertices of G can be ordered in such a way that both graphs are identical. Let ISO = { G , H : G and H are isomorphic graphs}. Show that ISO NP.

任务

Tasks

7.13

7.13 Let

MODEXP = { a , b , c , p a , b , cp是正二进制数,使得a b == c (mod p )}。

MODEXP = { a , b , c , p : a , b , c and p are positive binary numbers such that a b c (mod p )}.

证明MODEXP P。(请注意,最明显的算法不会在多项式时间内运行。提示:首先尝试b是 2 的幂的情况。)

Show that MODEXP P. (Note that the most obvious algorithm does not run in polynomial time. Hint: First try the case where b is a power of 2.)

7.14 集合 {1, …, k } 的排列是该集合自身的一对一函数。如果p是排列,则p t表示将p放在一起t次。让

7.14 A permutation of the set {1, …, k } is a one-to-one function onto itself. If p is a permutation, then p t denotes a t -fold composition of p with itself. Let

PERM-POWER = { p , q , t : p = q t,其中pq是集合 {1, …, k } 的排列,t是二进制整数}。

PERM-POWER = { p , q , t : p = q t , where p and q are permutations of the set {1, …, k }, and t is a binary integer}.

证明PERM-POWER ∈ P。(请注意,最明显的算法不会在多项式时间内运行。提示:首先考虑t是 2 的幂时的情况。)

Show that PERM-POWER P. (Note that the most obvious algorithm does not run in polynomial time. Hint: First consider the case when t is a power of 2.)

7.15 证明P类由于星号操作而封闭。 (提示:使用动态规划。对于输入词y = y 1 ... y n,其中y i Σ,构建一个数组,指示对于每个ij子词y i ... y j ​​∈ A *对于任何A P。)

7.15 Show that the class P is closed under the asterisk operation. (Hint: Use dynamic programming. For an input word y = y 1 y n , where y i Σ , construct an array indicating for each ij whether the subword y i y j A * for any A P.)

A 7.16 表明类 NP 由于星号操作而封闭。

A 7.16 Show that the class NP is closed under the asterisk operation.

7.17UNARY-SSUM为子集和问题的一个变体,其中所有数字均表示为一元。为什么SUBSET-SUM问题的 NP 完备证明没有表明UNARY-SSUM是 NP 完备的?证明UNARY-SSUM P。

7.17 Let UNARY-SSUM be a variant of the subset sum problem in which all numbers are represented unary. Why does the NP-completeness proof for the SUBSET-SUM problem not show that UNARY-SSUM is NP-complete? Prove that UNARY-SSUM P.

7.18 证明如果 P = NP,则除了 A = ØA = Σ *之外,每种语言A P都是 NP 完备的。

7.18 Prove that if P = NP, then every language A P except A = Ø and A = Σ * is NP-complete.

*7.19 证明PRIMES = { m : m是二元素数} NP。 (提示:对于p > 1,乘法群Z * p = { x : x与p互质,并且 1 ≤  p } 是循环群,并且当且仅当p是素数时,其阶数为p − 1。您可以采用没有证明的事实。更强的陈述PRIMES P 也是正确的,但它的证明要困难得多。)

*7.19 Show that PRIMES = { m : m is prime in binary notation} NP. (Hint: For p > 1, the multiplicative group Z * p = { x : x is coprime to p and 1 ≤  p } is cyclic and has order p − 1 if and only if p is prime. You can accept this fact without proof. The stronger statement that PRIMES P is also true, but its proof is much more difficult.)

7.20 一般认为PATH问题不是NP完备问题。解释这个信念的基础是什么。表明证明PATH问题不是 NP 完备问题将使我们能够证明 P NP。

7.20 It is generally believed that the PATH problem is not NP-complete. Explain why this is the case. Show that proving that the PATH problem is not NP-complete would allow one to prove that P NP.

7.21G是无向图。我们定义问题

7.21 Let G be an undirected graph. We define problems

SPATH = { G , a , b , k : G包含一条从ab的直路径,长度至多为k },

SPATH = { G , a , b , k : G contains a simple path from a to b of length at most k },

and

LPATH = { G , a , b , k G包含从ab的长度至少为k的直路径}。

LPATH = { G , a , b , k : G contains a simple path from a to b of length at least k }.

a. 证明SPATH P。

a. Prove that SPATH P.

b. 证明LPATH问题是NP 完备问题。

b. Prove that the LPATH problem is NP-complete.

7.22DOUBLE-SAT = { Φ〉 : Φ至少有两个满足 } 的评估。证明DOUBLE-SAT问题是 NP 完备问题。

7.22 Let DOUBLE-SAT = { Φ〉 : Φ has at least two valuations satisfying}. Prove that the DOUBLE-SAT problem is NP-complete.

A 7.23HALF-CLIQUE = { <G> G是一个无向图其中存在一个至少包含m/2个顶点的团其中m是G的顶点数}。证明HALF-CLIQUE问题是 NP 完备问题。

A 7.23 Let HALF-CLIQUE = {G : G is an undirected graph such that there is a clique with at least m /2 vertices, where m is the number of vertices of G }. Prove that the HALF-CLIQUE problem is NP-complete.

7.24CNF k = { 〈Φ〉Φ是一个可满足的 CNF 公式,其中每个变量最多出现 k 次}。

7.24 Let CNF k = { 〈Φ〉 : Φ be a satisfiable CNF formula in which each variable appears at most k times}.

a. 证明CNF 2 P。

a. Show that CNF 2 P.

b. 证明CNF 3是 NP 完备的。

b. Prove that CNF 3 is NP-complete.

7.25CNF H = { 〈Φ>Φ是一个可满足的 CNF 公式,其中每个子句包含任意数量的文字,最多其中一个被否定}。证明CNF H P。

7.25 Let CNF H = { 〈Φ〉 : Φ be a satisfiable CNF formula in which each clause contains an arbitrary number of literals, of which at most one is negated}. Show that CNF H P.

7.26Φ为 3CNF 形式的公式。 -变量求值Φ是每个子句包含两个具有不同逻辑值的文字的求值。换句话说, -valuation 满足公式Φ,但同时它不会将值 TRUE 分配给任何子句的所有三个文字。

7.26 Let Φ be a formula in the form 3CNF. A ≠ -valuation of variables Φ is a valuation in which each clause contains two literals with distinct logical values. In other words, the ≠ -valuation satisfies the formula Φ , but at the same time does not assign TRUE to all three literals for any clause.

a. 证明≠ -赋值也是 - 赋值。

a. Show that the negation of a -assignment is also a ≠ -assignment.

b.-SAT为具有 - 赋值的 3CNF 公式集。证明我们可以通过替换每个子句c来获得3SAT问题到SAT的多项式约简

b. Let -SAT be the set of 3CNF formulas that have -assignment. Show that we can obtain a polynomial reduction of the 3SAT problem to SAT by replacing each clause c and

( y 1 y 2 y 3 )

( y 1 y 2 y 3 )

两个条款

two clauses

( y 1 y 2 _ z i ) ( z i y 3 b ),

( y 1 y 2 _ z i ) ( z i y 3 b ),

其中z i是每个子句c i的单独变量,b是所有子句共用的单个附加变量。

where z i is a separate variable for each clause c i , and b is a single additional variable common to all clauses.

c. 由上可知问题SAT是 NP 完备问题。

c. Conclude from the above that the problem SAT is NP-complete.

7.27无向图中的 是将顶点集V划分为两个不相交的子集 S 和 T。割的大小是一端在 S 另一端在 T 的边的数量。令

7.27 A cut in an undirected graph is a partition of a set of vertices V into two disjoint subsets S and T. The size of the cut is the number of edges with one endpoint in S and the other in T. Let

MAX-CUT = { G , k G的切割大小为k或更大}。

MAX-CUT = { G , k : G has a cut of size k or larger}.

证明MAX-CUT问题是 NP 完备问题。您可以假设问题 7.26 的结果是已知的。 (提示:证明SATP MAX-CUT 。 x的变量 gadget是 3 个标记为x的c个顶点和另外 3 个标记为x 的顶点的集合,其中c是子句的数量。标记为x的所有顶点都连接到所有由x表示的顶点。子句小工具是一个由三个边组成的三角形,这些边连接着该子句中出现的用文字标记的三个顶点。不要在多个子句小工具中使用相同的顶点。)

Show that the MAX-CUT problem is NP-complete. You may assume that the result of Problem 7.26 is known. (Hint: Show that SATP MAX-CUT . The gadget of a variable x is the set of 3c vertices labeled x and another 3c vertices labeled x , where c is the number of clauses. All vertices labeled x are connected to all vertices labeled x . The gadget of a clause is a triangle of three edges connecting the three vertices labeled with the literals in the clause. Do not use the same vertex in more than one gadget of a clause. Prove that this reduction is correct.)

7.28 我们有一个盒子和一组卡片,如下所示。由于盒子中的销钉和卡片上的切口,每张卡片可以通过两种方式之一放置在盒子中。每张卡片包含两列孔,其中一些可能尚未打孔。该拼图涉及将所有卡片放入盒子中,以完备覆盖其底部(即每个孔至少被一张在该位置没有孔的卡片堵塞)。设PUZZLE = { c 1 , …, ck 〉其中每个ci代表一张卡片,并且这组卡片有一个解决方案}。证明PUZZLE问题是 NP 完备问题。

7.28 We have a box and a set of cards as shown below. Because of the pegs in the box and the cutouts in the cards, each card can be placed in the box in one of two ways. Each card contains two columns of holes, some of which may not have been punched through. The puzzle consists in placing all the cards in the box so as to completely cover the bottom of the box (i.e., each hole is blocked by at least one card that does not have a hole in that location). Let PUZZLE = { c 1 , …, c k : where each c i represents a card and this set of cards has a solution}. Prove that the problem PUZZLE is NP-complete.

7.29图形 着色是将颜色分配给顶点,使得没有两个相邻顶点具有相同的颜色。让

7.29 A graph coloring is an assignment of colors to vertices such that no two adjacent vertices have the same color. Let

3COLOR = { <G> G可以用3种颜色}

3COLOR = { G : the graph G can be colored with 3 colors}.

证明3COLOR问题是 NP 完备问题。 (提示:使用下面显示的三个子图。)

Prove that the 3COLOR problem is NP-complete. (Hint: Use the three subgraphs shown below.)

7.30SET-SPLITTING = { S, C :S 是有限集,C = { C 1 , …, C k } 是 S 的子集集合,其中k > 0 使得 S 的元素可以是颜色为红色蓝色,因此没有C i的所有元素都具有相同的颜色}。证明SET-SPLITTING问题是 NP 完备问题。

7.30 Let SET-SPLITTING = { S, C 〉 : S is a finite set, and C = { C 1 , …, C k } is a set of subsets of S such that the elements of S can be colored red or blue , so that no C i has all elements of the same color}. Prove that the SET-SPLITTING problem is NP-complete.

7.31 考虑以下调度问题。我们得到一个考试列表F 1 , …, F k和一个学生列表S 1 , …, S l。每个学生都会参加这些考试的某些特定子集。考试应安排好时间,以便没有学生同时参加两场考试。问题是判断是否存在只使用h个时间窗口的调度。将这个问题表述为一种语言并证明它是 NP 完备的。

7.31 Consider the following scheduling problem. We are given a list of exams F 1 , …, F k and a list of students S 1 , …, S l . Each student takes some specified subset of these exams. The exams must be scheduled so that no student has two exams at the same time. The problem is to determine whether there is a scheduling that uses only h time slots. State this problem as a language and show that it is NP-complete.

7.32 下面的问题受到单人游戏扫雷的启发,推广到任何图。设G是一个无向图,其中每个顶点要么包含一个隐藏的矿井,要么为空。玩家一一选择顶点。如果它选择了一个包含地雷的顶点,它就会失败。如果它选择一个空顶点,它会找出其相邻顶点中有多少个包含地雷。 (相邻顶点是通过一条边连接到所选顶点的顶点。)当玩家成功选择所有空顶点时,他就获胜。

7.32 The following problem is inspired by the single-player game Minesweeper , generalized to any graph. Let G be an undirected graph in which each vertex either contains a hidden mine or is empty. The player selects vertices one by one. If he selects a vertex containing a mine, he loses. If he selects an empty vertex, he learns how many of its neighboring vertices contain mines. (A neighboring vertex is one that is connected by an edge to the chosen vertex.) The player wins if he manages to select all empty vertices.

扫雷一致性问题 中,我们给出一个图G,其中一些顶点被分配了编号。需要确定是否可以在剩余的顶点中布置地雷,使得分配了编号m的每个顶点v恰好有m个包含地雷的相邻顶点。将这个问题表述为一种语言并证明它是 NP 完备的。

In the Minesweeper connectivity problem , we are given a graph G where some vertices are assigned numbers. We want to determine whether it is possible to arrange mines on the remaining vertices such that each vertex v with assigned number m has exactly m neighboring vertices containing mines. State this problem as a language and show that it is NP-complete.

A 7.33 在“孤独者”游戏中,我们有一个尺寸为m × m的棋盘。每个平方米的方块要么有一颗蓝色石头,要么有一颗红色石头,要么是空的游戏涉及从棋盘上移走棋子,直到每列仅包含一种颜色的棋子并且每行包含至少一个棋子。当玩家成功实现这一目标时,他就获胜了。获胜可能会也可能不会取决于您的初始设置。设SOLITAIRE = {G : G是获胜的游戏配置}。证明SOLITAIRE问题是 NP 完备问题。

A 7.33 In the game of solitaire, we have a board of dimensions m × m . Each of the m 2 squares contains either a blue stone, a red stone, or an empty square. The game consists of removing stones from the board until every column contains only stones of one color and every row contains at least one stone. The player wins when he manages to achieve this goal. Winning may or may not be possible depending on the initial configuration. Let SOLITAIRE = {G : G be a winning configuration of the game}. Prove that the SOLITAIRE problem is NP-complete.

7.34 回想一下,在讨论丘奇-图灵假设时,我们引入了语言D = { p p是一个具有整数根的多元多项式}。我们已经说过,但没有证明,语言D是不可判定的。在这个问题中,需要证明D语言的另一个性质——即D语言是NP-hard的。如果属于 NP 类的所有问题都可以在多项式时间内还原为该类,即使该问题本身不是 NP,则该问题称为NP 难问题。因此,有必要证明所有属于NP类的问题都可以多项式化简为D。

7.34 Recall that in discussing the Church–Turing conjecture, we introduced the language D = { p : p is a polynomial in several variables that has an integer root}. We have stated, but not proven, that the language D is undecidable. In this problem, we need to prove another property of the language D —namely, that the language D is NP-hard. A problem is called NP-hard if all problems in the class NP are reducible to it in polynomial time, even if the problem itself is not in NP. So we need to prove that all problems in the class NP are polynomial-time reducible to D .

7.35如果 图G的所有其他顶点都与该子集的某个顶点相邻,则图G的顶点子集是支配集。让

7.35 A subset of vertices of a graph G is a dominating set if every other vertex of G is adjacent to some vertex from the subset. Let

DOMINATING-SET = { G , k G包含一个具有k 个顶点的支配集}。

DOMINATING-SET = { G , k : G contains a dominating set with k vertices}.

通过展示VERTEX-COVER问题的简化证明该问题是 NP 完备问题。

Show that this problem is NP-complete by showing a reduction from the VERTEX-COVER problem .

*7.36 证明以下问题是 NP 完备问题。给定一组状态Q ={ q 0 , q 1 , …, q l } 和一组对 {( s 1 , r 1 ), …, ( s k , r k )},其中s是字母表中的不同单词Σ = {0, 1} 和r是Q的(不一定不同)元素。需要确定是否存在有限自动机M = ( Q , Σ , δ, q 0 , F ),其中对于每个i δ( q 0 , s i ) = r i。 δ( q , s ) 表示机器M在读取单词s后达到的状态,并在状态q中开始操作。 (请注意,集合F与此问题无关。)

*7.36 Show that the following problem is NP-complete. We are given a set of states Q = { q 0 , q 1 , …, q l } and a set of pairs {( s 1 , r 1 ), …, ( s k , r k )}, where s i are distinct words over the alphabet Σ = {0, 1} and r i are (not necessarily distinct) elements of Q . We want to determine whether there exists a finite automaton M = ( Q , Σ , δ, q 0 , F ), where δ( q 0 , s i ) = r i for all i . By δ( q , s ) we denote the state that M enters after reading word s , starting in state q . (Note that the set F is irrelevant in this problem.)

7.37 令 U = { M , x , # t:一台非确定性图灵机M沿着至少一个计算路径在t步中接受x }。请注意,并不要求M在所有路径上都停止。证明问题 U 是 NP 完备的。

7.37 Let U = { M , x , # t : a nondeterministic Turing machine M accepts x in t steps on at least one computation path}. Note that there is no requirement that M halt on all paths. Show that the problem U is NP-complete.

*7.38 证明如果 P = NP,则存在一种多项式时间算法,可以产生满足给定可满足逻辑公式的评估。 (注意:我们需要找到的算法是计算一个函数;然而,NP 类包含语言,而不是函数。P = NP 假设意味着SAT问题属于 P,因此可满足性测试可以在多项式时间内解决。但是,这个假设并没有告诉我们如何执行这个测试以及这样的检查是否揭示了任何可满足的评估,因此我们需要证明我们无论如何都可以找到它。提示:重复可满足性测试以找到适当的逐位分配。 )

*7.38 Show that if P = NP, then there is a polynomial-time algorithm that produces a satisfying valuation for a given satisfiable Boolean formula. (Note: The algorithm we are to find computes a function; however, the class NP contains languages, not functions. The assumption P = NP implies that the SAT problem is a member of P, so testing for satisfiability is solvable in polynomial time. However, this assumption does not tell us how to perform the test or whether such testing reveals any satisfying valuation. So we need to show that we can find one anyway. Hint: Apply the satisfiability test repeatedly to find the appropriate bit-by-bit assignment.)

*7.39 证明如果 P = NP,则存在一种在多项式时间内因式分解素数的算法。 (参见问题 7.38 的注释。)

*7.39 Prove that if P = NP, then there exists an algorithm that factors numbers into prime factors in polynomial time. (See the note to Problem 7.38.)

A* 7.40 证明如果 P = NP,则存在一个多项式算法,对于给定的无向图,找到该图中包含的最大团。 (参见问题 7.38 的注释。)

A* 7.40 Prove that if P = NP, then there is a polynomial-time algorithm that, given an undirected graph, finds the largest clique contained in that graph. (See the note to Problem 7.38.)

7.41 在库克-莱文定理的证明中,窗口被定义为大小为 2 × 3 的单元格矩形。请说明为什么如果我们使用 2 × 2 窗口,证明会不正确。

7.41 In the proof of the Cook–Levin theorem, a window is defined as a rectangle of 2 × 3 cells. Show why the proof would be invalid if we used 2 × 2 windows instead.

*7.42 考虑采用 DFA M作为输入并返回 DFA M'的MINIMIZE算法。

*7.42 Consider the MINIMIZE algorithm that takes a DFA M as input and returns a DFA M' .

MINIMIZE = "对于输入词M ,其中M = ( Q , Σ , δ, q 0 , A ) 是确定性有限自动机:

MINIMIZE = "For input word M , where M = ( Q , Σ , δ, q 0 , A ) is a deterministic finite automaton:

1.从初始状态中 删除所有无法到达的M状态。

1. Remove all states M that cannot be reached from the initial state.

2. 构造如下无向图G ,其顶点为机器M的状态。

2. Construct the following undirected graph G whose vertices are states of the machine M .

3. 用边将每个接受状态与每个非接受状态连接起来。然后添加更多边,如下所示。

3. Connect every accepting state with every non-accepting state with an edge. Then add more edges as below.

3. 重复直到可以将新边添加到G

3. Repeat until a new edge can be added to G :

5.对于机器M的 每对不同状态qr以及每个a Σ

5. For each pair of different states q and r of the machine M and each a Σ :

6.如果该图中存在边(δ ( q , a ), δ ( r , a)),则向G 添加边(q , r) 。

6. Add an edge ( q , r ) to G if there is an edge (δ( q , a ), δ( r , a)) in this graph.

7. 对于每个状态q,令 [ q ] 为状态集 [ q ] = { r Q:图G没有边连接qr }。

7. For each state q , let [ q ] be a set of states [ q ] = { r Q : no edge of G connects q and r }.

8. 创建一个新的有限机M' = ( Q' , Σ , δ', q 0 ', A '),其中Q' = {[ q ] : q Q } (if [ q ] = [ r ],那么 Q' 只能属于其中之一), δ'([ q ], a ) = [δ( q , a )] 对于每个q Qa 2 Σ , q 0 ' = [ q 0 ] 和A ' = {[ q ] : q A }。

8. Create a new finite automaton M' = ( Q' , Σ , δ', q 0 ', A '), where Q' = {[ q ] : q Q } (if [ q ] = [ r ], only one of them can belong to Q'), δ'([ q ], a ) = [δ( q , a )] for every q Q and a 2 Σ , q 0 ' = [ q 0 ] and A' = {[ q ] : q A }.

9. 写出 M' ”。

9. Print M' ”.

a. 证明M和M'是等价的。

a. Prove that M and M' are equivalent.

b. 表明机器 M' 是最小的,即没有更少状态的有限机器能够识别相同的语言。您可以使用问题1.52的结果,而无需证明它。

b. Prove that the automaton M' is minimal, that is, that no finite automaton with fewer states recognizes the same language. You can use the result of Exercise 1.52 without proving it.

c. 显示MINIMIZE算法在多项式时间内运行。

c. Show that the MINIMIZE algorithm runs in polynomial time.

7.43 证明对于包含m 个变量和c 个子句的 CNF 公式Φ,可以在多项式时间内构造一个包含 O( cm ) 状态的非确定性有限自动机,该自动机接受所有不令人满意的评估,表示为长度为m的二进制字。推论如果P NP,则意味着非确定性有限自动机无法在多项式时间内最小化。

7.43 Show that for a CNF formula Φ with m variables and c clauses, one can construct in polynomial time a nondeterministic finite automaton with O( cm ) states that accepts all nonsatisfying valuations, represented as binary words of length m . Conclude that if P NP, this implies that the nondeterministic finite automaton cannot be minimized in polynomial time.

*7.44 2CNF 形式的公式是子句的合取,其中每个子句是至多两个文字的析取。令2SAT = { 〈Φ〉 : Φ是 2CNF} 的可满足公式。证明 2SAT P。

*7.44 A formula in the form 2CNF is a conjunction of clauses, where each clause is a disjunction of at most two literals. Let 2SAT = { 〈Φ〉 : Φ be a satisfiable 2CNF formula}. Show that 2SAT P.

7.45 修改定理 7.16 证明中提出的上下文无关语言识别算法,以获得为给定单词和上下文无关语法创建分区树的多项式算法,前提是该语法生成​​该单词。

7.45 Modify the context-free language recognition algorithm given in the proof of Theorem 7.16 so as to obtain a polynomial-time algorithm that produces a parse tree for a given word and a context-free grammar if that grammar generates the word.

7.46如果两个逻辑公式包含相同的变量集并且对这些变量的相同评估都成立(即它们描述相同的逻辑函数),则 我们说这两个逻辑公式是等价的。如果不存在更短的等效公式,则逻辑公式是最小的。令MIN-FORMULA为最小逻辑公式的集合。证明如果 P = NP,则MIN-FORMULA P。

7.46 We say that two logical formulas are equivalent if they contain the same set of variables and are true for the same valuations of those variables (that is, they describe the same logical function). A logical formula is minimal if there is no shorter equivalent formula. Let MIN-FORMULA be the set of minimal logical formulas. Prove that if P = NP, then MIN-FORMULA P.

7.47我们递归地定义 微分层次DP 如下:

7.47 We define the differential hierarchy D and P recursively as follows:

D 1 P = NP 且

a. D 1 P = NP and

b. DP = { A : A = B \ C,其中B属于 NP,C属于 D-1 P}。 (我们假设B \ C = B C。)

b. D and P = { A : A = B \ C for B belonging to NP and C belonging to D and −1 P}. (We assume that B \ C = B C .)

例如,D 2 P 类的语言是 NP 类的两种语言的差异。 D 2 P 类有时称为 DP(也写作 D P)。让

For example, a language from class D 2 P is the difference of two languages ​​from class NP. Class D 2 P is sometimes called DP (and is also written as D P ). Let

Z = { < G 1 , k 1 , G 2 , k 2 > : G 1具有k 1 -团且G 2不包含k 2 -团}。

Z = { G 1 , k 1 , G 2 , k 2 : G 1 has a k 1 -clique and G 2 does not have a k 2 -clique}.

证明Z在 DP 类中是完备的。换句话说,证明 Z 属于 DP 类,并且属于 DP 类的每种语言都可以多项式约简到 Z。

Prove that Z is complete in the class DP. In other words, prove that Z is a member of the class DP and that every language of the class DP is polynomially reducible to Z.

*7.48MAX-CLIQUE = { G , k 〉 :图G中最大的团的大小恰好为k }。使用问题 7.47 的结果表明MAX-CLIQUE问题是 DP 完备问题。

*7.48 Let MAX-CLIQUE = { G , k : the largest clique in G has size exactly k }. Use the result of Problem 7.47 to show that MAX-CLIQUE is DP-complete.

*7.49f : N N为满足f ( n ) = o ( n log n ) 且f ( n ) ≥ n的任意函数。证明 TIME( f ( n )) 类仅包含正则语言。

*7.49 Let f : N N be any function for which f ( n ) = o ( n log n ) and f ( n ) ≥ n . Show that the class TIME( f ( n )) contains only regular languages.

*7.50如果正则表达式不包含星号操作(Kleene 闭包),则 该正则表达式被称为无星型。令EQ SF−REX = { R , S R和 S 是等价的无星正则表达式}。证明EQ SF−REX属于 coNP 类。为什么这个证明不适用于一般的正则表达式?

*7.50 A regular expression is called star-free if it does not contain an asterisk operation (Kleene's closure). Let EQ SF−REX = { R , S : R and S are equivalent star-free regular expressions}. Show that EQ SF−REX belongs to the class coNP. Why does this proof not work for general regular expressions?

*7.51 在这个问题中,我们将处理消解,即以 CNF 形式证明公式不可满足性的方法。令Φ = C 1 C 2 ^ ^ C m为 CNF 形式的公式,其中C是子句。令C = { C i : C i是Φ的子句}。在一个解析步骤中,我们采用属于C的两个子句C aC b,使得某个变量x在其中一个中未被否定,而在另一个中也被否定。这意味着C a = ( x y 1 y 2 y k ) 和C b = ( x z 1 z 2 _ z l ),其中y iz i是文字。我们创建一个新子句 ( y 1 y 2 y kz 1 z 2 z l ),删除重复的文字。我们将这个新子句添加到C中。我们重复解决步骤,直到无法获得附加条款为止。如果C包含一个空子句 ( ),我们得出结论:公式Φ不可满足。

*7.51 In this problem we deal with resolution , a method for proving the unsatisfiability of CNF formulas. Let Φ = C 1 C 2 ^ ^ C m be a CNF formula, where C i are clauses. Let C = { C i : C i is a clause of Φ }. In one step of resolution we take two clauses C a and C b of C , such that some variable x is unnegated in one of them and negated in the other. This means that C a = ( x y 1 y 2 y k ) and C b = ( x z 1 z 2 _ z l ), ​​where y i and z i are literals. We create a new clause ( y 1 y 2 y k z 1 z 2 z l ), ​​removing repeated literals. We add this new clause to C . We repeat the resolution step until no additional clause can be obtained. If C contains an empty clause ( ), then we conclude that the formula Φ is unsatisfiable.

如果一个解决方案从未显示出实际上可满足的公式的不可满足性,我们就说它是正​​确的。如果一个解决方案对于每个不可满足的公式都显示出它的不可满足性,我们也会说该解决方案是完整的。

We say that a resolution is sound if it never demonstrates the unsatisfaction of formulas that are in fact satisfiable. We also say that a resolution is complete if, for every unsatisfiable formula, it demonstrates its unsatisfaction.

a. 表明所提出的决议是正确且完整的。

a. Prove that the resolution presented is correct and complete.

b. 使用 (a) 部分证明2SAT P。

b. Use part (a) to show that 2SAT P.

*7.52如果对于任何a Σ f ( a ) ≠ ε , 同态是非擦除的。证明当且仅当 P = NP 时,类 P 在非擦除同态下是封闭的。

*7.52 A homomorphism is non-erasing if f ( a ) ≠ ε for any a Σ . Show that the class P is closed under non-erasing homomorphisms if and only if P = NP.

*7.53A 1 *为一元语言。证明如果A是 NP 完备的,则 P = NP。 (提示:考虑 f 从SATA 的多项式约简。对于公式Φ,令Φ 0100为公式,其中公式Φ的变量x 1x 2x 3x 4被赋值​分别为 0、1、0 和 0。如果我们将函数f应用于所有这些指数级多个公式,对于变量Φ的所有部分评估,会发生什么情况?)

*7.53 Let A 1 * be a unary language. Show that if A is NP-complete, then P = NP. (Hint: Consider the polynomial reduction f from SAT to A . For a formula Φ , let Φ 0100 be a formula in which the variables x 1 , x 2 , x 3 , and x 4 of the formula Φ are assigned the values ​​0, 1, 0, and 0, respectively. What happens if we apply the function f to all such exponentially many formulas, for all partial valuations of the variables Φ ?)

7.54有向图中顶点的 输入度是进入该顶点的边数,输出度是离开该顶点的边数。证明以下问题是NP完备问题。给定一个无向图G及其顶点的子集C,是否可以通过指定每条边的方向,使得属于C的每个顶点的输入度为 0 或输出度为 0,将G转换为有向图, G 的所有其他顶点的输入度至少为 1?

7.54 The indegree of a vertex in a directed graph is the number of edges entering the vertex, and the outdegree is the number of edges leaving the vertex. Show that the following problem is NP-complete. Given an undirected graph G and a subset C of its vertices, is it possible to transform G into a directed graph by defining the directions of each edge such that every vertex in C has either indegree 0 or outdegree 0, and all other vertices of G have indegree at least 1?

精选解决方案

Selected solutions

7.1 ( c ) 错误; ( d ) 正确。

7.1 ( c ) FALSE; ( d ) TRUE.

7.2 ( c ) 正确; ( d ) 正确。

7.2 ( c ) TRUE; ( d ) TRUE.

7.16A NP。我们将构造一个非确定性图灵机M ,它在多项式时间内解析语言A *。

7.16 Let A NP. We construct a nondeterministic Turing machine M that decides the language A * in polynomial time.

M =“对于中的输入词:

M = "For input word in :

1. 如果w = ε,则接受

1. If w = ε, accept .

2. 非确定性地将单词w分为几个部分w = x 1 x 2 x k

2. Nondeterministically split the word w into parts w = x 1 x 2 x k .

3. 对于每个x i,不确定地猜测显示x i A的证书。

3. For each x i , nondeterministically guess a certificate showing that x i A .

4. 验证所有证书。如果正确,请接受。如果验证失败,请拒绝

4. Verify all certificates. If they are correct, accept . If verification failed, reject ”.

7.23我们提出了CLIQUEHALF-CLIQUE问题 的多项式时间简化。约简函数的参数是对< G , k >,它产生下面的图<H>作为输出如果Gm 个顶点且k = m /2,则 H = G。如果k < m /2,则 H 是通过添加j 个顶点从G获得的图,每个顶点连接到每个原始顶点以及添加的每个剩余顶点,其中j = m − 2k。因此 H 有m + j = 2m − 2k 个顶点。请注意,G具有k -clique 当且仅当 H 包含大小为k + j = mk的 clique 时,因此G , k CLIQUE当且仅当 H HALF-CLIQUE。如果k > m /2,则 H 是在图G上添加j 个顶点而没有任何附加边而获得的图,其中j = 2k − m。因此 H 有m + j = 2k 个顶点,因此G包含k团当且仅当 H 包含大小为k的团。因此G , k CLIQUE当且仅当 H HALF-CLIQUE。还需要证明HALF-CLIQUE NP。您所需要做的就是选择适当的团体来获取证书。

7.23 We present a polynomial-time reduction of CLIQUE to HALF-CLIQUE . The argument of the reduction function is a pair G , k and it produces as output the following graph H . If G has m vertices and k = m /2, then H = G . If k < m /2, then H is the graph obtained from G by adding j vertices, each of which is connected to each of the original vertices and to each of the remaining added vertices, where j = m − 2k. Thus H has m + j = 2m − 2k vertices. Note that G has a k -clique if and only if H contains a clique of size k + j = mk , and therefore G , k CLIQUE if and only if H HALF-CLIQUE . If k > m /2, then H is the graph obtained by adding j vertices to G without any additional edges, where j = 2k − m . Thus H has m + j = 2k vertices, and so G contains a k -clique if and only if H contains a clique of size k . Hence G , k CLIQUE if and only if H HALF-CLIQUE . It remains to show that HALF-CLIQUE NP. It is enough to take the appropriate clique as a certificate.

7.33 首先,我们可以注意到SOLITAIRE NP,因为我们可以在多项式时间内检查解是否正确。其次,我们将证明3SATP SOLITAIRE。给定具有m个变量x 1 , …, x mk 个子句c 1 , …, ck 的公式Φ ,我们将在k × m棋盘上构建以下游戏G。我们假设Φ不包含同时包含x ix i的子句,因为可以删除此类子句而不影响可满足性。

7.33 First, we can see that SOLITAIRE NP, since we can check in polynomial time whether the solution is correct. Second, we will show that 3SATP SOLITAIRE . Given a formula Φ with m variables x 1 , …, x m and k clauses c 1 , …, c k , we construct the following game G on a k × m board . We assume that Φ does not contain clauses in which x i , and x i appear simultaneously , since such clauses can be deleted without affecting satisfiability.

如果x i出现在子句c j中,我们将蓝色石头放在x i列的c j行中。如果文字x i出现在本子句中,我们就在x i列的c j行放置一颗红色棋子。我们可以通过重复行或添加空列来使棋盘成为正方形,而不影响解的存在性。我们将证明当且仅当博弈G有解时,公式Φ是可满足的。

If x i appears in clause c j , we place a blue stone in row c j of column x i . If this clause contains a literal x i , we place a red stone in row c j of column x i . We can make the board square by repeating rows or adding empty columns, without affecting the existence of a solution. We will show that the formula Φ is satisfiable if and only if the game G has a solution.

( ) 假设有一个令人满意的估值。如果x为 TRUE(分别为 FALSE),那么我们从相应的列中删除红色(蓝色)棋子。因此,与值为 TRUE 的文字相对应的宝石将保留。由于每个子句至少包含一个计算结果为 TRUE 的文字,因此每一行中至少有一个石头。

( ) Suppose there is a satisfying valuation. If x i is TRUE (FALSE, respectively), then we remove the red (blue) stones from the corresponding column. This leaves stones corresponding to literals with the value TRUE. Since each clause contains at least one literal with the value TRUE, there is at least one stone in each row.

(←) 假设游戏有一个解决方案。如果红色(蓝色)石头已从列中移除,我们将相应变量的值设置为 TRUE(FALSE)。每行中都有一些剩余的石头,因此每个子句都包含一个值为 TRUE 的文字。因此,满足公式Φ 。

(←) Suppose the game has a solution. If the red (blue) stones have been removed from a column, we set the value of the corresponding variable to TRUE (FALSE). Each row has a remaining stone, so each clause contains a literal with the value TRUE. Thus, the formula Φ is satisfied.

7.40 如果我们假设 P = NP,则CLIQUE P,并且我们可以在多项式时间内检查图G是否包含对于任意k值的大小为k的团。通过依次检查G是否包含从 1 到G 的顶点数的连续大小的团,我们可以在多项式时间内确定G中最大团的大小t 。一旦我们知道t ,我们就可以找到一个具有t 个顶点的团,如下所示。对于属于G 的每个顶点x 我们删除x并计算结果图的最大团大小。如果获得的尺寸较小,我们恢复顶点x并检查下一个顶点。如果结果大小仍然是t,我们永久删除顶点x并继续处理没有该顶点的图。一旦以这种方式检查了所有顶点,剩下的顶点就形成了t团。

7.40 If we assume that P = NP, then CLIQUE P and we can check in polynomial time whether G contains a clique of size k for any value of k . By successively checking whether G contains cliques of sizes 1 through the number of vertices in G , we can determine the size t of the maximal clique in G in polynomial time. Once we know t , we can find a clique of t vertices as follows. For each vertex x in G, we remove x and calculate the maximal clique size for the resulting graph. If the resulting size is smaller, we restore vertex x and check the next vertex. If the resulting size is still t , we permanently remove vertex x and continue with the graph without that vertex. After checking all vertices in this way, the remaining ones form a t -clique.

8

内存复杂度

8

Memory Complexity

在本章中,我们将解决内存需求方面计算问题的复杂性。在寻找许多计算问题的实际解决方案时,所需的时间和内存是两个最重要的考虑因素。内存复杂度与时间复杂度共享许多特征,并可作为根据计算难度进一步对问题进行分类的一种方法。

In this chapter, we will consider the complexity of computational problems from the perspective of memory requirements. Time and memory requirements are two of the most important considerations when looking for practical solutions to many computational problems. Memory complexity shares many features with time complexity and serves as a way to further classify problems by their computational difficulty.

与时间复杂度一样,我们需要选择一个模型来测量算法使用的内存。我们将继续使用图灵机模型,其原因与我们使用它来测量时间复杂度的原因相同。图灵机在数学上很简单,并且足够接近真实的计算机,因此结果很有价值。

As with time complexity, we need to choose a model for measuring the memory used by the algorithm. We will continue to use the Turing machine model for the same reasons we used it to measure time complexity. Turing machines are mathematically simple and close enough to real computers that their results are valuable.

定义 8.1

Definition 8.1

M为确定性图灵机,每次输入都会停止。机器M的内存复杂度是函数f : N N,其中f ( n ) 是机器M读取长度为n的任何输入字的磁带单元的最大数量。如果机器M的内存复杂度为f ( n ),那么我们也说机器M在内存f ( n )中运行。

Let M be a deterministic Turing machine that halts for every input. The memory complexity of M is a function f : N N , where f ( n ) is the maximum number of tape cells that M reads for any input word of length n . If the memory complexity of M is f ( n ), then we also say that M operates on memory f ( n ).

如果M是一个非确定性图灵机,对于所有计算路径上的每个输入都会停止,那么我们将其内存复杂度f ( n ) 定义为机器M在任何计算路径上对于任何长度的输入字读取的磁带单元的最大数量名词

If M is a nondeterministic Turing machine that halts for every input on all computation paths, then we define its space complexity f ( n ) to be the maximum number of tape cells read by M on any of the computation paths for any input word of length n .

我们通常会使用渐近符号来估计图灵机的内存复杂度。

We will typically estimate the memory complexity of Turing machines using asymptotic notation.

定义 8.2

Definition 8.2

f : N R +为函数。我们定义内存复杂度类 SPACE( f ( n ))NSPACE( f ( n ))

Let f : N R + be a function. We define the space complexity classes SPACE( f ( n )) and NSPACE( f ( n )) :

SPACE( f ( n )) = { L : L是一种由确定性图灵机解析的语言,其内存复杂度为O ( f ( n ))}。

SPACE( f ( n )) = { L : L is a language that is decipherable by a deterministic Turing machine with space complexity O ( f ( n ))}.

NSPACE( f ( n )) = { L : L是一种由非确定性图灵机解析的语言,内存复杂度为O ( f ( n ))}。

NSPACE( f ( n )) = { L : L is a language that is decided by a nondeterministic Turing machine with space complexity O ( f ( n ))}.

8.3

Example 8.3

第7章我们介绍了NP完备SAT问题。现在我们将证明SAT可以通过需要线性内存的算法来解决。人们相信SAT问题不能用多项式时间算法来解决,更不用说线性算法了,因为SAT是一个 NP 完备问题。内存似乎是比时间强大得多的资源,因为与时间不同,它可以重复使用。

In Chapter 7, we introduced the NP-complete problem of SAT . We now show that SAT can be solved by an algorithm that requires linear memory. It is widely believed that SAT cannot be solved by a polynomial-time algorithm, much less a linear one, because SAT is NP-complete. It seems that memory is a much more powerful resource than time, because, unlike time, it can be reused.

M 1 = "对于输入词<Φ>,其中Φ是逻辑公式:

M 1 = "For input word 〈Φ〉 , where Φ is a logical formula:

  1. 对于变量x 1 , …, x m的每次评估,公式Φ
  2. For each valuation of variables x 1 , …, x m the formula Φ :
  3. 计算本次评估的Φ 值。
  4. Calculate the value of Φ for this valuation.
  5. 如果某些评估的Φ为 1,则接受;否则丢弃。”
  6. If Φ for some valuation is 1, accept ; otherwise reject ."

很明显,M 1在线性存储器中运行,因为它可以在循环的每次迭代中使用磁带的相同部分。机器只需要存储变量的当前评估,并且可以使用O ( m )量级的内存来完成此操作。变量的数量m最多等于n,即输入字的长度,因此机器在O ( n ) 内存中运行。

It is clear that M 1 operates in linear memory, since it can use the same portion of the tape in each iteration of the loop. The machine only needs to store the current value of the variables, and it can do this in O ( m ) memory. The number of variables m is at most n , the length of the input word, so the machine operates in O ( n ) memory .

8.4

Example 8.4

我们现在提出一个语言的非确定性记忆复杂性的例子。在下一节中,我们将展示如何使用非确定性内存复杂性估计来估计确定性内存复杂性。现在考虑检查非确定性有限状态机 (NFA) 是否接受所有单词的问题。让

We now provide an example of the nondeterministic memory complexity of a language. In the next section, we show how the estimate of the nondeterministic memory complexity can be used to estimate the deterministic memory complexity. Now consider the problem of checking whether a nondeterministic finite automaton (NFA) accepts all words. Let

ALL NFA = { A A是 NFA 且L ( A ) = Σ * }。

ALL NFA = { A : A is an NFA and L ( A ) = Σ * }.

我们将提出一种具有线性内存复杂度的非确定性算法,用于解析该语言的补集,即ALL NFA。这个想法是使用非确定性来猜测 NFA 拒绝的单词,并使用线性内存来存储 NFA 在特定时间点可能处于的状态。请注意,我们不知道我们的语言属于 NP 还是 coNP 类。

We will present a nondeterministic algorithm of linear memory complexity that decides the complement of this language, namely ALL NFA . The idea is to use nondeterminism to guess the word rejected by the NFA and use linear memory to store the states that this NFA may be in at a particular moment. Note that it is not known whether our language belongs to the class NP or coNP.

N = "对于输入词M ,其中M是一个非确定性有限自动机:

N = "For input word M , where M is a nondeterministic finite automaton:

  1. 在初始 NFA 状态中放置一个标记。
  2. Place a marker in the NFA initial state.
  3. 重复 2 q次,其中q是机器M的状态数:
  4. Repeat 2 q times, where q is the number of states of the automaton M :
  5. 非确定性地选择一个输入符号并更改机器状态M上的标记位置以模拟读取该符号。
  6. Nondeterministically choose an input symbol and change the positions of the tags on the machine states M to simulate reading that symbol.
  7. 如果步骤 2 和 3 已确定M拒绝的某个单词,即,如果没有任何标签处于接受M 的任何状态,则接受。否则,丢弃。”
  8. Accept if steps 2 and 3 have determined some word that is rejected by M , that is, if neither token is ever in one of the states that accept M . Otherwise, reject ”.

如果机器M拒绝任何单词,它也必须拒绝长度最多为 2q 的某个单词因为在每个被拒绝的较长单词中,算法中描述的标签排列将被重复。可以删除这些放置的重复之间的单词部分,从而产生更短的丢弃单词。因此,机器N解析ALL NFA。 (请注意,机器N也接受无效输入词。)

If machine M rejects some words, then it must also reject some word of length at most 2q , since in each longer rejected word the token arrangements described by the algorithm will be repeated. The part of the word that falls between the repetitions of these arrangements can be removed, obtaining a shorter rejected word. Thus machine N resolves ALL NFA . (Note that machine N also accepts invalid input words.)

该算法仅需要存储器来存储标记放置和循环计数器,可以在线性存储器中实现。因此,该算法在非确定性O ( n ) 内存中运行。稍后,我们将证明一个定理,该定理将提供有关ALL NFA的确定性内存复杂性的信息。

This algorithm only needs memory to store the token placement and the loop counter, which can be implemented in linear memory. Thus, this algorithm runs in nondeterministic memory O ( n ). Later we prove a theorem that provides information about the deterministic memory complexity of ALL NFA .

8.1

萨维奇定理

8.1

Savitch's Theorem

萨维奇定理是关于记忆复杂性的最早结果之一。它指出确定性机器可以使用极少的内存来模拟非确定性机器。在时间复杂度的情况下,这样的模拟似乎需要时间呈指数增长。对于内存复杂性萨维奇定理表明,任何使用f ( n ) 内存的非确定性图灵机都可以转化为只需要f2 ( n ) 内存的确定性图灵机。

Savitch's theorem is one of the earliest results concerning memory complexity. It states that deterministic machines can simulate nondeterministic machines using surprisingly little memory. In the case of time complexity, such a simulation seems to require an exponential increase in time. For memory complexity, Savitch's theorem shows that any nondeterministic Turing machine using f ( n ) memory can be transformed into a deterministic Turing machine that needs only f2 ( n ) memory.

定理8.5

Theorem 8.5

萨维奇定理 对于任意1函数f : N R +,其中f ( n ) ≥ n ,NSPACE( f ( n )) SPACE( f 2 ( n ))。

Savitch's Theorem For any 1 function f : N R + , where f ( n ) ≥ n , NSPACE( f ( n )) SPACE( f 2 ( n )).

证明的概念我们想要使用确定性机器来模拟具有内存复杂度f ( n ) 的非确定性图灵机一种简单的方法是按顺序尝试非确定性机器的所有计算路径。模拟必须记住当前正在检查哪条路径,以便移动到下一条。然而,使用f ( n ) 存储器的路径可能会经历 2 O( f ( n ))个步骤,并且每个步骤都可能是非确定性选择。按顺序探索这些路径需要记住您在特定路径上所做的所有选择,以便找到下一条路径。因此,这种方法可能需要 2 O( f ( n ))内存,远远超出我们的O ( f 2 ( n )) 内存目标。

Proof Concept We wish to simulate a nondeterministic Turing machine of memory complexity f ( n ) using a deterministic machine. A naive approach would be to try all the computation paths of the nondeterministic machine in sequence. The simulation must remember which path it is currently trying in order to proceed to the next one. However, a path using memory f ( n ) may take 2 O( f ( n )) steps, and each step may be a nondeterministic choice. Sequentially examining these paths would require remembering all the choices made on a given path in order to find the next one. Thus, this approach would require 2 O( f ( n )) memory , far exceeding our goal of O ( f 2 ( n )) memory.

相反,我们将通过考虑更普遍的问题来采取不同的方法。我们有两个 NTM 配置,c 1c 2,以及一个数字t,我们想要检查 NTM 是否能够在不超过t步内仅使用f ( n ) 内存从c 1c 2 。我们将这个问题称为可达性问题。通过解决c 1为初始配置、c 2为接受配置、t为非确定性机器可以采取的最大步数的情况下的可达性问题,我们可以确定机器是否接受输入单词。

Instead, we will take a different approach by considering a more general problem. We are given two NTM configurations, c 1 and c 2 , and a number t , and we want to check whether the NTM can go from c 1 to c 2 in no more than t steps, using only f ( n ) of memory. We will call this problem the reachability problem . By solving the reachability problem for the case where c 1 is the initial configuration, c 2 is the accepting configuration, and t is the maximum number of steps that a nondeterministic machine can take, we can determine whether the machine accepts an input word.

我们将提出一种确定性的递归算法来解决可达性问题。它的工作原理是找到cm中间配置并递归检查是否 (1)最多可以在t /2 步内从c 1cm ,以及 (2)最多可以在t /2内从cmc 2 t /2步。为每个递归测试重复使用内存可以显着节省内存。

We present a deterministic, recursive algorithm for solving the reachability problem. It works by finding an intermediate configuration c m and recursively checking whether (1) one can get from c 1 to c m in at most t /2 steps, and (2) one can get from c m to c 2 in at most t /2 steps. Reusing memory for each of the recursive tests allows for significant memory savings.

该算法需要内存来存储递归调用的堆栈。每级递归都使用 O( f ( n )) 内存来存储配置。递归深度为 log t,其中t是非确定性机器在任何路径上采取的最大步骤数。我们有t = 2 O( f ( n )),因此 log  O ( f ( n ))。因此,确定性模拟使用O ( 2 ( n )) 内存。

This algorithm needs memory to store the recursive call stack. Each level of recursion uses O( f ( n )) memory to store the configuration. The recursion depth is log t , where t is the maximum number of steps that the nondeterministic machine takes on any path. We have t = 2 O( f ( n )) , and therefore log  O ( f ( n )). Thus, deterministic simulation uses O ( 2 ( n )) memory.

证明 N是在内存f ( n )中解析语言A 的非确定性图灵机解析语言 A 的确定性图灵机M。机器M使用CANYIELD过程,该过程检查机器N的一个配置是否可以在指定的步骤数内到达另一个配置。该过程解决了证明概念中描述的可达性问题。

Proof Let N be a nondeterministic Turing machine deciding language A in memory f ( n ). We construct a deterministic Turing machine M deciding language A. The machine M uses the procedure CANYIELD , which tests whether one of the machine configurations N can be reached from another in a specified number of steps. This procedure solves the reachability problem described in the proof concept.

w为机器N的输入词。对于机器N的配置c 1c 2以及整数t,如果N可以在t或更少的步骤中遵循从配置c 1到配置c 2 的某些非确定性计算路径,则过程CANYIELD ( c 1 , c 2 , t ) 返回接受。如果不是,CANYIELD返回拒绝。为了方便起见,我们假设t是 2 的幂。

Let w be an input word of machine N . For configurations c 1 and c 2 of machine N and an integer t, the procedure CANYIELD ( c 1 , c 2 , t ) returns accept if N can follow some nondeterministic computation path from configuration c 1 to configuration c 2 in t or fewer steps. If not, CANYIELD returns reject . For convenience, we assume that t is a power of 2.

CANYIELD =“对于给定的配置c 1c 2和数字t

CANYIELD = "For given configurations c 1 , c 2 and number t :

  1. 如果t =1,则根据机器的传递函数N ,直接检查c 1是否= c 2或者c 1是否可以一步从c 2 到c 2。如果这些测试中的任何一个成功,请接受;如果两者都失败,则丢弃.
  2. If t = 1, check directly whether c 1 = c 2 or whether c 1 can be moved to c 2 in one step, according to the transition function of machine N . If either of these tests succeeds, accept ; if both fail, reject .
  3. 如果t > 1,则对于机器N每个配置cm在内存f ( n )中执行以下操作:
  4. If t > 1, then for each configuration c m of machine N perform the following operations in memory f ( n ):
  5. 执行CANYIELD ( c 1 , cm , t / 2)。
  6. Perform CANYIELD ( c 1 , c m , t /2).
  7. 执行CANYIELD ( cm , c 2 , t / 2)。
  8. Perform CANYIELD ( c m , c 2 , t /2).
  9. 如果步骤 3 和 4 的结果均为接受,则接受
  10. If the outcome of both steps 3 and 4 is acceptance, then accept .
  11. 如果输入尚未被接受,则拒绝。”
  12. If the input has not been accepted yet, reject ."

我们现在定义一个机器M来模拟机器N。首先,我们将修改N,以便在接受时,它清除其磁带并将磁头移动到最左边的单元格 - 我们将此配置称为c Accept。令c start为机器N的单词 w 的初始配置,我们选择常数d,使得机器N使用内存f ( n )具有不超过 2 个df ( n )配置,其中n是单词w的长度。我们知道 2 df ( n )是机器N在单词w的任何计算路径上运行时间的上限。

We now define a machine M that simulates machine N . First, we modify N so that upon acceptance it clears its tape and moves the head to the leftmost cell—we will call this configuration c accept . Let c start be the initial configuration of machine N for word w. We choose a constant d such that machine N has no more than 2 df ( n ) configurations using memory f ( n ), where n is the length of word w . We know that 2 df ( n ) is an upper bound on the running time of machine N on any path of computation for word w .

M =“对于中的输入词:

M = "For input word in :

  1. 返回过程CANYIELD ( c start , c accept , 2 df ( n ) )的结果。”
  2. Return the result of procedure CANYIELD ( c start , c accept , 2 df ( n ) )".

CANYIELD算法显然解决了可达性问题,因此机器M正确地模拟了机器N。我们只需要确保M在内存中运行O ( 2 ( n )) 即可。

The CANYIELD algorithm obviously solves the reachability problem, and therefore machine M correctly simulates machine N . We only need to ensure that M runs in memory O ( 2 ( n )).

每当CANYIELD被递归调用时,它都会将返回地址和值c 1c 2t保存在堆栈上,以便在递归调用返回时可以重新创建这些值。因此,每一级递归都使用O ( f ( n )) 额外内存。此外,每一级递归都将数量t分成两半。最初t等于 2 df ( n ),因此递归深度为O (log 2 df ( n ) ),即O ( f ( n ))。由此可见,如定理所示,所使用的总内存为O ( 2 ( n ))。

Whenever CANYIELD is called recursively, it stores the return address and the values ​​c 1 , c 2 , and t on the stack , so that these values ​​can be restored upon return from the recursive call. Hence, each level of recursion uses O ( f ( n )) of additional memory. Moreover, each level of recursion divides the size of t in half. Initially , t is equal to 2 df ( n ) , so the recursion depth is O (log 2 df ( n ) ), or O ( f ( n )). This implies that the total memory used is O ( 2 ( n )), as in the theorem.

这种推理有一个技术难题,因为M算法在调用CANYIELD时必须知道f ( n )的值。我们可以通过修改机器M来依次测试值f ( n ) = 1, 2, 3, ...来解决这个困难。对于f ( n ) = i的每个值,修改后的算法使用CANYIELD来确定接受配置是否可达。此外,该算法使用CANYIELD来检查N是否正在使用至少i + 1 个内存(磁带单元),检查是否可以从初始配置实现任何长度为i +1 的配置。如果接受配置可达,则 M接受;如果没有长度为i +1 的配置可达,则M丢弃;否则M继续计算f ( n ) = i + 1。(我们可以用另一种方式处理这个问题,假设M可以使用O ( f ( n )) 内存计算f ( n ),但是我们必须添加这个定理假设的条件。)

There is one technical difficulty in this reasoning, since the algorithm M must know the value of f ( n ) when it calls CANYIELD . We can deal with this difficulty by modifying the machine M so that it successively tests the values ​​f ( n ) = 1, 2, 3, … . For each value of f ( n ) = i , the modified algorithm uses CANYIELD to determine whether the accepting configuration is reachable. Additionally, the algorithm uses CANYIELD to check whether N uses at least i + 1 memory (tape cells), checking whether any configuration of length i + 1 can be reached from the initial configuration. If the accepting configuration is reachable, M accepts; if no configuration of length i + 1 is reachable, M rejects; otherwise M continues to work for f ( n ) = i + 1. (We could handle this problem in a different way, assuming that M can compute f ( n ) using O ( f ( n )) of memory, but then we would have to add this condition to the assumptions of the theorem.)

8.2

PSPACE类

8.2

PSPACE Class

我们定义内存复杂度的 PSPACE 类与 P 类类似。

We define the memory complexity class PSPACE analogously to the class P.

定义 8.6

Definition 8.6

PSPACE是一类可由多项式内存中的确定性图灵机判定的语言。换句话说,

PSPACE is a class of languages ​​that are decidable by deterministic polynomial-memory Turing machines. In other words,

NPSPACE 类,即 PSPACE 的非确定性等价物,由 NSPACE 类的概念类似地定义。然而,从萨维奇定理我们知道 PSPACE = NPSPACE,因为平方多项式仍然是多项式。

The class NPSPACE, the nondeterministic counterpart of PSPACE, is defined analogously by the notion of NSPACE classes. However, from Savitch's theorem we know that PSPACE = NPSPACE, since a polynomial squared is still a polynomial.

在示例 8.3 和 8.4 中,我们表明SAT问题属于 SPACE( n ),并且ALL N F A属于 coNSPACE( n ),因此根据萨维奇定理属于 SPACE( n 2 ),因为确定性内存复杂性类由于 for 而被封闭完成。因此,这两种语言都属于PSPACE类。

In Examples 8.3 and 8.4 we showed that the SAT problem belongs to SPACE( n ) and that ALL NF A belongs to coNSPACE( n ), and therefore by Savitch's theorem to SPACE( n 2 ), since the deterministic memory complexity classes are closed under complement. Hence, both of these languages ​​belong to the class PSPACE.

让我们探讨一下 PSPACE、P 和 NP 类之间的关系。我们可以看到 P   PSPACE 因为运行时间短的机器不可能消耗太多内存。更准确地说,对于t ( n ) ≥ n ,在时间t ( n )运行的任何机器最多可以使用t ( n ) 内存,因为机器在每个计算步骤中最多可以访问一个新单元。类似地,可以证明 NP NPSPACE,因此 NP   PSPACE。

Let us examine the relation between the classes PSPACE, P, and NP. We can see that P   PSPACE, since a machine that runs for a short time cannot use up too much memory. More precisely, for t ( n ) ≥ n, any machine running for time t ( n ) can use up at most t ( n ) memory, since the machine can visit at most one new cell in each computational step. Analogously, one can show that NP NPSPACE, and hence NP   PSPACE.

我们还可以通过内存复杂度来限制图灵机的时间复杂度。对于f ( n ) ≥ n ,使用f ( n ) 内存的图灵机最多有f ( n ) 2 O ( f ( n ))种不同的配置,这可以通过第 5.8 页引理证明的简单概括来表示222. 在停止图灵机的计算中不能重复任何配置。由此可见,使用内存f ( n ) 的图灵机2必须在时间f ( n ) 2 O( f ( n ))内运行,因此 PSPACE EXPTIME = k TIME(2 n k )。

We can also bound the time complexity of a Turing machine by its memory complexity. For f ( n ) ≥ n, a Turing machine using f ( n ) memory has at most f ( n ) 2 O( f ( n )) different configurations, which can be shown by a simple generalization of the proof of Lemma 5.8 on page 222. In the computations of a halting Turing machine, no configurations can be repeated. This implies that a Turing machine 2 using f ( n ) memory must run in time f ( n ) 2 O( f ( n )) , so PSPACE EXPTIME = k TIME(2 n k ).

我们对迄今为止定义的计算复杂性类别之间关系的了解可以概括为一系列包含

Our knowledge of the relationships between the computational complexity classes defined so far can be summarized as a series of inclusions

P NP PSPACE = NPSPACE EXPTIME。

P NP PSPACE = NPSPACE EXPTIME.

我们不知道这些结论是否实际上是平等的。也许有人会发现一种类似于萨维奇定理中所示的模拟,它将其中一些类合并为一个。然而,在第 9 章我们将证明 P EXPTIME。因此,所显示的合同中至少有一份是正确的,但我们无法判断哪一份!事实上,大多数研究人员认为所有这些结论都是合适的。下图说明了这些类之间的关系,假设它们都不同。

We don't know whether any of these inclusions are actually equality. Perhaps someone will find a simulation similar to the one shown in Savitch's theorem that combines some of these classes into one. However, in Chapter 9 we will prove that P EXPTIME. This means that at least one of the inclusions shown is proper, but we cannot say which one! In fact, most researchers believe that all of these inclusions are proper. The diagram below illustrates the relationships between these classes, assuming that they are all distinct.

8.7

P、NP、PSPACE 和 EXPTIME 类之间的假定关系

Figure 8.7.

Assumed relations between classes P, NP, PSPACE and EXPTIME.

8.3

PSPACE完整性

8.3

PSPACE-completeness

在7.4节中,我们介绍了NP完备语言这一类别,作为属于NP类的最难语言的代表。证明一种语言是 NP 完备的,这提供了该语言不属于 P 类的强有力的例子。如果属于 P 类,那么 P 和 NP 将是相等的。在本节中,我们将介绍 PSPACE 类的 PSPACE 完整性的类似概念。

In Section 7.4 we introduced the category of NP-complete languages ​​as representatives of the most difficult languages ​​belonging to the class NP. Showing that a language is NP-complete provides a strong premise that the language is not a member of the class P. If it were, then P and NP would be equal. In this section we introduce the analogous notion of PSPACE-completeness for the class PSPACE.

定义8.8

Definition 8.8

如果语言B满足两个条件,则它是PSPACE 完备的:

A language B is PSPACE-complete if it satisfies two conditions:

  1. 语言B属于PSPACE类。
  2. The B language belongs to the PSPACE class.
  3. 属于 PSPACE 类的每种语言A都可以多项式时间约简到语言B。
  4. Every language A belonging to the class PSPACE is reducible in polynomial time to language B .

如果语言B只满足条件 2,我们说它是PSPACE-hard

If language B satisfies only condition 2, then we say that it is PSPACE-hard .

在 PSPACE 完整定义中,我们使用从定义 7.29 导出的形式的多项式时间约简。为什么我们不定义多项式时间 缩减的概念,而是使用多项式时间缩减?为了理解这个重要问题的答案,让我们首先考虑为什么我们首先定义完整的问题。

In the definition of PSPACE-completeness, we used the polynomial-time reduction in the form derived from Definition 7.29. Why do we not define the notion of reduction in polynomial space and instead use polynomial- time reduction ? To understand the answer to this important question, let us first consider the reasons for defining complete problems in the first place.

完整的问题很重要,因为它们是相应计算复杂度类别中最困难问题的示例。完整问题是最困难的,因为给定类中的所有其他问题都可以相对容易地简化为它。因此,如果我们能找到一种简单的方法来解决一个完整的问题,我们将能够同样轻松地解决此类的所有其他问题。与课堂上典型问题的复杂性相比,这种简化必须很容易,这样才有意义。如果归约本身在计算上是困难的,那么完整问题的简单解决方案不一定会转化为解决可以归约到它的问题的简单性。

Complete problems are important because they are examples of the most difficult problems in their respective classes of computational complexity. A complete problem is the most difficult because every other problem in the class can be reduced to it relatively easily. Therefore, if we can find an easy way to solve a complete problem, then we can solve all other problems in the class just as easily. A reduction must be easy relative to the complexity of typical problems in the class in order to make sense. If the reduction itself were computationally difficult, then an easy solution to a complete problem would not necessarily translate into an easy solution to those problems that can be reduced to it.

遵循以下规则:在为复杂性类定义完整问题时,所使用的简化模型必须比用于定义此类本身的模型更受限制。

This implies the following rule: when defining complete problems for a complexity class, the reduction model used must be more restricted than the model used to define that class itself.

TQBF问题

TQBF problem

我们的 PSPACE 完备问题的第一个示例涉及可满足性问题的概括。回想一下,逻辑公式是包含逻辑变量、常量 0 和 1 以及逻辑运算 ^、 和 Ø 的表达式。现在我们将介绍一种更通用的逻辑公式。

Our first example of a PSPACE-complete problem concerns a generalization of the satisfiability problem. Recall that a logical formula is an expression containing logical variables, the constants 0 and 1, and the logical operations ^, , and ¬. We now introduce a more general type of logical formula.

量词 每个人)和)经常出现在数学句子中。符号x Φ表示语句Φ对于变量x的每个值都为真(满足)。类似地,符号x Φ表示对于变量x的某个值,语句Φ为真。量词有时称为一般通用)量词,而 -特定存在)量词。我们说紧跟在量词后面的变量受该量词约束

Quantifiers ( for each ) and ( exists ) often appear in mathematical sentences. The notationx Φ means that the sentence Φ is true (fulfilled) for every value of the variable x . Similarly, the notationx Φ means that the sentence Φ is true for some value of the variable x . The quantifier is sometimes called a general ( universal ) quantifier, while is called a specific ( existential ) quantifier. We say that the variable immediately following the quantifier is bound by this quantifier .

例如,考虑关于自然数∀ x [ x + 1 > x ]的陈述,这意味着任何自然数x的后继x + 1都大于该数字。这句话当然是正确的。另一方面,表达式y [ y + y = 3] 肯定是假的。在解释包含量词的句子的含义时,我们必须考虑变量值来自哪个宇宙)。在所示的例子中,定义域是自然数;如果我们使用实数,则包含特定量词的句子将变为真。

For example, consider the sentence about the natural numbers x [ x + 1 > x ], which means that the successor x + 1 of any natural number x is greater than that number. This sentence is obviously true. On the other hand, the expression y [ y + y = 3] is clearly false. When interpreting the meaning of sentences containing quantifiers, we must take into account what domain ( universe ) the values ​​of the variables come from. In the examples shown, the domain is the natural numbers; if we had used the real numbers instead, the sentence containing the particular quantifier would be true.

一个句子可以包含多个量词,例如x y [ y > x ]。在自然数域的情况下,这句话指出对于每个自然数都有一个比它大的自然数。句子中量词的顺序很重要。颠倒顺序后,如句子y x [ y > x ] 中,我们得到完备不同的含义 - 即某个自然数大于所有其他自然数。很明显第一句话是正确的,第二句话是错误的。

A sentence can contain several quantifiers, for example x y [ y > x ]. In the case of the domain of natural numbers, this sentence states that for every natural number there is a natural number greater than it. The order of the quantifiers in the sentence is important. When the order is reversed, as in the sentence y x [ y > x ], we get a completely different meaning – namely, that some natural number is greater than all the others. It is obvious that the first sentence is true and the second is false.

数学句子中的量词可以出现在任何地方。它涉及由一对括号或方括号分隔的句子片段,后面是量词变量。我们称这个片段为量词的范围。要求所有量词出现在句子的开头并且每个量词的范围是其后面的整个短语(句子的一部分)通常是很方便的。这种句子形式称为prenex 范式。每个句子都可以很容易地简化为 prenex 范式。除非另有说明,我们只会考虑这种形式的句子。

A quantifier in a mathematical sentence can appear anywhere. It concerns a fragment of the sentence enclosed by a pair of parentheses or square brackets, following the quantifier variable. This fragment is called the scope of the quantifier. It is often convenient to require that all quantifiers appear at the beginning of the sentence and that the scope of each quantifier is the entire formulation (part of the sentence) that follows it. This form of sentence is called prenex normal form . Any sentence can be easily reduced to prenex normal form. We will only consider sentences in this form unless we say otherwise.

除典型元素外还包含量词的逻辑公式称为量词的逻辑公式。此类公式中变量的域是集合{0, 1}。例如

Logical formulas that contain quantifiers in addition to the typical elements are called quantifier logical formulas . The domain of variables in such formulas is the set {0, 1}. For example

Φ = x y [( x _ y ) ( x y )]

Φ = x y [( x _ y ) ( x y )]

是带有量词的逻辑公式。在这种情况下,Φ是一个真实的公式,但如果我们颠倒量词xy的顺序,它就会变成假的。

is a logical formula with quantifiers. In this case Φ is a true formula, but it would become false if we swapped the order of the quantifiers x and y .

如果公式中的每个变量都出现在某个量词的范围内,我们就说该公式没有自由变量或者它是完备量化的(所有变量都受到限制)。这样的公式有时被称为命题,它们总是要么为真,要么为假。上面的Φ公式包含了所有涉及的变量。然而,如果我们从Φ中删除初始部分x,它将不再被完备量化,并且可以取 TRUE 和 FALSE 值。

If every variable in a formula occurs within the scope of some quantifier, then we say that the formula has no free variables or that it is fully quantified (has all variables bound). Such formulas are sometimes called propositions and are always either true or false. The above formula Φ has all variables bound. However, if we were to remove the leading part x from Φ , it would no longer be fully quantified and could take on the value either TRUE or FALSE.

TQBF问题是确定所提出的没有自由变量的逻辑公式是真还是假。我们将定义语言

The TQBF problem is to determine whether a given logical formula without free variables is true or false. We define the language

TQBF = { 〈Φ〉 : Φ是一个没有自由变量的真逻辑公式}。

TQBF = { 〈Φ〉 : Φ is a true logical formula with no free variables}.

定理8.9

Theorem 8.9

TQBF问题是 PSPACE 完备问题。

The TQBF problem is PSPACE-complete.

证明的概念 为了证明TQBF问题属于 PSPACE,我们将展示一个简单的算法,该算法为变量赋值并递归检查这些值的公式值。有了这些信息,算法就可以确定原始量化公式的真实性。

Concept of Proof To show that the TQBF problem belongs to PSPACE, we show a simple algorithm that assigns values ​​to variables and recursively checks the value of a formula for those values. Given this information, the algorithm can determine the truth of the original formula with quantifiers.

为了证明任何PSPACE语言A都可以在多项式时间内简化为TQBF ,我们从语言A的图灵机开始,在多项式有界内存中运行。然后,我们将展示多项式时间约简,将这种语言的单词转换为量化的逻辑公式Φ,该公式对该输入单词的机器模拟进行编码。当且仅当机器接受这个词时,这个公式才成立。

To show that any PSPACE language A can be reduced to a TQBF in polynomial time, we start with a Turing machine for the language A , operating on polynomial-time bounded memory. We then show a polynomial-time reduction that transforms a word of that language into a quantified Boolean formula Φ that encodes a simulation of that machine for that input word. This formula is true if and only if the machine accepts that word.

在这种构造的第一种方法中,让我们尝试模仿库克-莱文定理的证明,即定理 7.37。我们可以构造一个公式Φ模拟机器M对于输入词w,表达接受画面的要求。机器M对于单词w的表的宽度为 O ( n k ),等于M使用的内存,但其高度相对于n k呈指数关系,因为机器M可以在指数时间内运行。这意味着如果我们想直接将表格表示为公式,我们最终会得到一个指数公式。然而,多项式约简不能产生指数大小的结果,因此我们无法证明AP TQBF

In a first approach to this construction, let us try to imitate the proof of the Cook–Levin theorem, Theorem 7.37. We can construct a formula Φ that simulates a machine M for input w by expressing the requirements for an accepting tableau. The tableau of a machine M for w is wide O ( n k ), which is equal to the memory used by M , but its height is exponential in n k , since M can run in exponential time. This means that if we were to represent the tableau directly as a formula, we would get a formula of exponential size. However, polynomial reduction cannot produce an exponential result, so this method fails to show that AP TQBF .

相反,我们将使用类似于萨维奇定理证明中使用的方法来构建公式。该公式将表格分成两半,并使用通用量词来表示公式同一部分中每一半的条件。结果将是一个更短的公式。

Instead, we will use a method analogous to the one used in the proof of Savitch's theorem to construct the formula. The formula divides the tableau into halves and uses a general quantifier to represent the terms for each half in the same part of the formula. The result will be a much shorter formula.

证明 首先,我们提出一个多项式内存运算。

Proof We first present a polynomial memory operation.

T = "对于输入词<Φ>,描述一个没有自由变量的逻辑公式:

T = "For an input word 〈Φ〉 , describing a logical formula without free variables:

  1. 如果公式Φ不包含量词,那么它是一个仅包含常量的表达式,因此评估Φ的值,如果为 TRUE,则接受;否则丢弃
  2. If the formula Φ contains no quantifiers, then it is an expression containing only constants, so evaluate Φ and accept if it is TRUE; reject otherwise .
  3. 如果公式Φ等于x φ ,则递归地调用Tφ,首先用 0 替换变量x,然后用 1替换。否则丢弃
  4. If the formula Φ is equal to x φ , then recursively invoke T for φ , substituting x first with 0 and then with 1. If you get an acceptance for any of the substitutions, accept ; otherwise reject .
  5. 如果公式Φ等于x φ,则递归调用 T 来表示φ,首先用 0 替换变量x 然后用 1替换。否则丢弃。”
  6. If the formula Φ is equal to x φ , then recursively invoke T for φ by substituting x first with 0 and then with 1. If both substitutions evaluate to acceptance, accept ; otherwise reject ".

很明显,T 解析了TQBF。分析它的内存复杂度,注意递归的深度最多就是变量的个数。在每一级我们只需要存储一个变量的值,因此总共使用的内存是O ( m ),其中m是Φ公式中的变量数量。这意味着 T 在线性有界内存中运行。

It is obvious that T is decided by TQBF . To analyze its memory complexity, note that the recursion depth is at most the number of variables. At each level we only need to store the value of one variable, so the total memory used is O ( m ), where m is the number of variables appearing in the formula Φ . This means that T operates on linearly bounded memory.

然后我们证明TQBF问题是 PSPACE 困难的。设A为某个图灵机M在内存n k中解析的语言,其中k是某个常数。我们将介绍语言A到 TQBF的多项式时间约简。

Next, we show that the TQBF problem is PSPACE-hard. Let A be a language negotiable by some Turing machine M with memory n k , where k is some constant. We show a polynomial-time reduction of A to TQBF.

约简将单词w转换为带有量词Φ 的逻辑公式,当且仅当M接受单词w时,该公式为真。为了展示公式Φ的构造,我们将解决一个更一般的问题。对于代表机器M的两种配置的两组变量c 1c 2以及某个数字t > 0,我们将构造公式Φ c 1, c 2, t。如果我们用实际配置替换c 1c 2 ,当且仅当机器M可以在最多t步内从配置c 1转到c 2时,该公式才成立。然后我们可以将Φ视为公式Φ c start , caccept , h,其中h = 2 df ( n )对于某个常数d选择,使得机器M具有不超过 2 df ( n )种可能的配置输入单词 o 长度n让我们假设f ( n ) = nk。为了方便起见,我们还假设t是 2 的幂。

Reduction transforms a word w into a logical formula with quantifiers Φ , which is true if and only if M accepts the word w . To show the construction of the formula Φ , we solve a more general problem. For two sets of variables c 1 and c 2 representing two configurations of the machine M , and some number t > 0, we construct the formula Φ c 1 , c 2 , t . If we substitute real configurations for c 1 and c 2 , this formula is true if and only if the machine M can go from configuration c 1 to c 2 in at most t steps. Then we can take Φ to be the formula Φ c start , c accept ,h , where h = 2 df ( n ) for some constant d chosen so that the machine M has no more than 2 df ( n ) possible configurations for an input word of length n . Let f ( n ) = n k . For convenience, we will also assume that t is a power of 2.

该公式以与库克-莱文定理的证明类似的方式对配置单元的内容进行编码。每个单元格都有几个与其关联的变量,一个变量代表每个磁带符号和状态,对应于该单元格的可能值。每个配置包含n k 个单元,因此可以用O ( n k ) 个变量进行编码。

The formula encodes the contents of the configuration cells in a similar way to the proof of the Cook–Levin theorem. Each cell has several variables associated with it, one for each tape symbol and state, corresponding to the possible values ​​of that cell. Each configuration contains n k cells, so it can be encoded using O ( n k ) variables.

如果t = 1,我们可以很容易地构造公式Φ c 1, c 2, t。该公式必须说明配置c 1等于c 2,或者c 2在机器M的一个步骤中从配置c 1得出。我们将通过创建一个逻辑表达式来表述相等性,该逻辑表达式表示表示c 1 的每个变量与表示c 2的相应变量具有相同的逻辑值。我们将使用库克-莱文证明中所示的技术来表达第二种可能性。换句话说,我们可以通过创建一个逻辑表达式来表示从配置c 1可以在机器M的单个步骤中从配置 c 1转到配置c 2 ,该逻辑表达式表明单元c 1的每个三元组的内容可以正确地表示转换为配置c 2的相应三元组单元的内容。

If t = 1, then we can easily construct the formula Φ c 1 , c 2 , t . This formula must state that either configuration c 1 is equal to c 2 , or c 2 results from configuration c 1 in one step of machine M . We state the equality by creating a logical expression stating that each of the variables representing c 1 has the same logical value as the corresponding variable representing c 2 . We express the second possibility using the technique shown in the Cook-Levin proof. In other words, we can express the fact that it is possible to go from configuration c 1 to c 2 in one step of machine M by creating a logical expression stating that the contents of each triple of cells c 1 can be correctly transformed into the contents of the corresponding triple of cells of configuration c 2 .

如果t > 1,那么我们将递归地建立公式Φ c 1, c 2, t。为了热身,让我们尝试一个不太正确的想法,但我们稍后会修复它。让

If t > 1, then we will construct the formula Φ c 1, c 2, t recursively. As a warm-up, let's try an idea that is not quite correct, but we will fix it later. Let

Φ c 1, c 2, t = m 1 [ Φ c 1, m 1, t /2 Φ m 1, c 2, t /2 ]

Φ c 1, c 2, t = m 1 [ Φ c 1, m 1, t /2 Φ m 1, c 2, t /2 ]

符号m 1表示机器M的配置。符号m 1是符号x 1 , …, x l的缩写,其中l = O ( n k ),并且x 1 , …, x l是编码配置m 1 的变量。因此,公式Φ c 1, c 2, t的这种构造表明,机器M最多可以在t步中从配置c 1转换到c 2,前提是存在某种中间配置m 1 ,机器M可以从配置 m 1 转换到该中间配置 m 1 。至多t /2步中配置c 1,然后至多t /2步中从配置m 1c 2 。我们递归地建立公式Φ c 1, m 1, t /2Φ m 1, c 2, t /2

The symbol m 1 represents a configuration of machine M . The notation m 1 is a shorthand for x 1 , …, x l , where l = O ( n k ), and x 1 , …, x l are variables encoding configuration m 1 . This construction of the formula Φ c 1, c 2, t therefore states that machine M can go from configuration c 1 to c 2 in at most t steps, provided there is some intermediate configuration m 1 to which machine M can go from configuration c 1 in at most t /2 steps, and then from configuration m 1 to c 2 in at most t /2 steps. We construct the formulas Φ c 1, m 1, t /2 and Φ m 1, c 2, t /2 recursively.

只要机器M最多可以在t步内从配置c 1转到配置c 2 ,公式Φ c 1, c 2, t就是有效的,即 TRUE。然而,这个公式太大了。其构造中使用的每一级递归都将t分为两半,但同时大约使公式的长度增加了一倍。因此,我们得到了一个大小大致等于t 的公式。最初t = 2 df ( n ),因此该方法将为我们提供一个指数大小的公式。

The formula Φ c 1 , c 2 , t has a valid value, that is, TRUE, if the machine M can go from configuration c 1 to c 2 in at most t steps. However, this formula is too large. Each level of recursion used in its construction halves t , but at the same time approximately doubles the length of the formula. This gives us a formula of size roughly equal to t . Initially, t = 2 df ( n ) , so this method will give us a formula of exponential size.

为了减小该公式的大小,我们将使用量词。让

To reduce the size of this formula, we will use the quantifiers and . Let

Φ c 1, c 2, t = m 1 ( c 3 , c 4 ) ε {( c 1 , m 1 ), ( m 1 , c 2 )} [ Φ c 3, c 4, t /2 ] 。

Φ c 1, c 2, t = m 1 ( c 3 , c 4 ) {( c 1 , m 1 ), ( m 1 , c 2 )} [ Φ c 3, c 4, t /2 ] .

引入表示c 3c 4配置的新变量使我们能够将两个递归子公式“焊接”为一个而不改变其原始含义。记号 ( c 3 , c 4 ) {( c 1 , m 1 ), ( m 1 , c 2 )} 表示表示配置c 3c 4的变量可以分别取变量的值根据配置c 1m 1以及m 1c 2,所得公式Φ c 3, c 4, t /2在每种情况下都将保持正确。我们可以用其等效结构x [ ( x = y x = z) … ]替换结构x { y , z} [ … ] 以获得句法正确的带有量词的逻辑公式。正如我们在 0.2 节中所记得的,逻辑蕴涵 ( ) 和逻辑相等 (=) 可以使用 AND 和 NOT 来表达。为了简化表示法,我们使用符号 = 来表示逻辑相等,而不是0.2 节中使用的等价符号↔ 。

The introduction of new variables representing configurations c 3 and c 4 allows us to "weld" two recursive subformulas into one without changing their original meaning. The notation ( c 3 , c 4 ) {( c 1 , m 1 ), ( m 1 , c 2 )} means that the variables representing configurations c 3 and c 4 can take on the values ​​of variables from configurations c 1 and m 1 and m 1 and c 2 , respectively , and the resulting formula Φ c 3, c 4, t /2 will remain true in each case. We can replace the construction x { y , z} [ … ] with its equivalent construction x [ ( x = y x = z) … ] to obtain a syntactically correct logical formula with quantifiers. As we remember from Section 0.2, logical implication ( ) and logical equality (=) can be expressed using the connectives AND and NOT. To simplify notation, we use the symbol = to denote logical equality instead of the equivalence symbol used in Section 0.2.

为了计算公式Φ c start, c Accept , h的大小,其中h = 2 df ( n ),我们可以注意到,每个递归级别都会添加公式的一部分,该部分的大小与配置,因此大小为O ( f ( n ) )。级别数为 log(2 df ( n ) ) 或O ( f ( n ))。因此,所得公式的大小为O ( f 2 ( n ))。

To calculate the size of the formula Φ c start, c accept , h , where h = 2 df ( n ) , we can note that each level of recursion adds a fragment of the formula with size linear in the size of the configuration, and thus with size O ( f ( n )). The number of levels is log(2 df ( n ) ), which is O ( f ( n )). Hence the size of the resulting formula is O ( f 2 ( n )).

游戏中的制胜策略

Winning strategies in games

就本章而言,我们可以将游戏定义为敌对双方试图按照既定规则实现特定目标的比赛。游戏有多种形式,从国际象棋等棋盘游戏到模拟企业或社会冲突的经济和战争游戏。

For the purposes of this chapter, we can define a game as a competition in which opposing sides attempt to achieve some goal by following established rules. Games come in many forms, from board games such as chess to economic and war games modeling corporate or social conflicts.

游戏与量词密切相关。带有量词的句子对应于某个游戏,反之,游戏往往对应于某个带有量词的句子。这些相互联系有很多好处。一是将带有多个量词的数学句子呈现为相应的游戏可以帮助理解该句子。另一方面,使用带有量词的数学句子来表达游戏有助于理解游戏的复杂性。为了说明博弈和量词之间的对应关系,我们将使用一种称为公式博弈的人工博弈

Games are closely related to quantifiers. A quantifier sentence often has a corresponding game, and conversely, a game often has a corresponding quantifier sentence. These interrelationships are helpful for several reasons. One is that representing a mathematical sentence with many quantifiers as a corresponding game can help us understand the sentence. On the other hand, expressing a game in terms of a mathematical sentence with quantifiers helps us understand the complexity of the game. To illustrate this correspondence between games and quantifiers, we will use an artificial game called a formula game .

Φ = x 1 x 2 x 3 Qx k [ φ ] 是带有 prenex 范式的量词的逻辑公式。这里的符号Q表示量词。下面的游戏就对应这个公式。两个玩家(我们将其表示为A和 E )轮流选择变量x 1 , ..., x k的值。玩家A选择与量词关联的变量的值,玩家E选择与量词关联的变量的值。移动顺序与公式开头的量词顺序相同。最后,我们使用玩家选择的值并得出结论,如果φ(即公式中删除量词后的部分)对于该变量评估为 TRUE,则玩家E获胜。如果φ为 FALSE,玩家A获胜。

Let Φ = x 1 x 2 x 3 Qx k [ φ ] be a Boolean formula with quantifiers in prefix normal form. The symbol Q here denotes the quantifier or . The following game corresponds to this formula. Two players, whom we will denote as A and  E , take turns choosing values ​​of variables x 1 , …, x k . Player A chooses values ​​of variables bound by quantifiers , and player E chooses values ​​of variables bound by quantifiers . The order of moves is the same as the order of quantifiers at the beginning of the formula. Finally, we use the values ​​chosen by the players and state that player E has won if φ , that is, the part of the formula after removing the quantifiers, is TRUE with this valuation of variables. Player A wins if φ is FALSE.

8.10

Example 8.10

Φ 1为公式

Let Φ 1 be the formula

x 1 x 2 x 3 [( x 1 x 2 ) ( x 2 x 3 ) ( x 2 x 3 )]。

x 1 x 2 x 3 [( x 1 x 2 ) ( x 2 x 3 ) ( x 2 x 3 )].

在公式为Φ 1的游戏中,玩家E选择变量x 1的值,然后玩家A选择变量x 2的值,最后玩家E选择值x 3

In the game with formula Φ 1, player E chooses the value of the variable x 1 , then player A chooses the value of the variable x 2 , and finally player E chooses the value x 3 .

为了说明示例游戏玩法,我们将像往常一样将逻辑值 TRUE 表示为 1,将 FALSE 表示为 0。假设玩家E选择x 1 = 1,然后玩家A选择x 2 = 0,最后玩家E选择x 3 = 1。利用这些值x 1x 2x 3得出子公式

To illustrate an example game, we will represent the logical value TRUE as 1 and FALSE as 0 as usual. Suppose player E chooses x 1 = 1, then player A chooses x 2 = 0 and finally player E chooses x 3 = 1. With these values ​​x 1 , x 2 and x 3 the subformula

( x 1 x 2 ) ( x 2 x 3 ) ( x 2 x 3 )

( x 1 x 2 ) ( x 2 x 3 ) ( x 2 x 3 )

值为 1,因此玩家E获胜。事实上,玩家E总是可以通过首先选择x 1 = 1,然后选择值x 3作为玩家A为变量x 2选择的值的否定来获胜。我们说玩家E在这场游戏中有必胜的策略。如果双方都采取最佳行动,则该玩家获胜,则该玩家具有获胜策略。

has value 1, so player E has won. In fact, player E can always win by first choosing x 1 = 1 and then choosing the value x 3 as the negation of what player A chooses for x 2 . We say that player E has a winning strategy in this game . A player has a winning strategy if that player wins when both sides make optimal moves.

现在我们将更改公式以获得玩家A具有获胜策略的游戏。设Φ 2为公式

We will now change the formula to obtain a game in which player A has a winning strategy. Let Φ 2 be the formula

x 1 x 2 x 3 [( x 1 x 2 ) ( x 2 x 3 ) ( x 2 x 3 )]。

x 1 x 2 x 3 [( x 1 x 2 ) ( x 2 x 3 ) ( x 2 x 3 )].

现在玩家A有了获胜策略,因为无论玩家E对变量x 1选择什么,玩家A都可以选择x 2 = 0,从而强制公式的量化部分为 FALSE,无论玩家E在最后的流量中选择什么。

Now player A has a winning strategy, since no matter what player E chooses for the variable x 1 , player A can choose x 2 = 0, forcing the quantified part of the formula to be FALSE, no matter what player E chooses in the last move.

我们现在考虑确定在涉及特定公式的游戏中是否以及哪个玩家有获胜策略的问题。让

We now consider the problem of determining whether and which player has a winning strategy in a game associated with a given formula. Let

FORMULA-GAME = { 〈Φ〉:玩家E在与Φ相关的公式游戏中有获胜策略。

FORMULA-GAME = { 〈Φ〉 : player E has a winning strategy in the formula game associated with Φ }.

定理8.11

Theorem 8.11

公式游戏问题是 PSPACE 完备问题。

The FORMULA-GAME problem is PSPACE-complete.

证明的概念公式游戏 问题是 PSPACE 完备的,原因很简单。这与TQBF是同样的问题。为了检查FORMULA-GAME = TQBF ,我们可以看到,当玩家E在相关游戏中具有获胜策略时,公式的计算结果为 TRUE这两个短语是表达同一件事的不同方式。

Concept of Proof The problem FORMULA-GAME is PSPACE-complete for a simple reason. It is the same problem as TQBF . To check that FORMULA-GAME = TQBF , we can note that the formula evaluates to TRUE just when player E has a winning strategy in the associated game. These two formulations are different ways of expressing the same thing.

证明如果变量x 1的值存在替换,使得对于变量x 2的任何替换,则 公式Φ =x 1 x 2 x 3 [ φ ] 为 TRUE变量x 3的值等等...使得最终φ公式对于该变量评估为 TRUE。,玩家E在涉及公式Φ的游戏中具有获胜策略,如果他可以将值分配给变量x 1 ,使得对于x 2值的任何设置他可以选择这样一个为该变量评估分配 TRUE

Proof The formula Φ =x 1 x 2 x 3 [ φ ] is TRUE, if there is such an assignment of the variable x 1 that for any assignment of the variable x 2 there is such an assignment of the variable x 3 and so on …, that eventually the formula φ is TRUE for this valuation of the variables. Similarly, player E has a winning strategy in the game associated with the formula Φ , if he can make such an assignment of the variable x 1 that for any setting of the values ​​of x 2 he will be able to choose such an assignment of the value of x 3 and so on, that eventually the formula φ is TRUE for this valuation of the variables.

相同的推理可以应用于特定量词和一般量词没有交替的公式。例如,如果公式Φx 1 , x 2 , x 3 x 4 , x 5 x 6 [ φ ],那么玩家A将进行前三步,为变量x 1赋值,x 2x 3;然后玩家E将进行两步操作,为变量x 4x 5赋值;最后玩家A将为变量x 6赋值。

The same reasoning can be applied to formulas that do not alternate between specific and general quantifiers. For example, if the formula Φ has the form x 1 , x 2 , x 3 x 4 , x 5 x 6 [ φ ], then player A will make the first three moves, assigning values ​​to variables x 1 , x 2 , and x 3 ; then player E will make two moves, assigning values ​​to variables x 4 and x 5 ; and finally player A will assign the value to variable x 6 .

因此,我们可以注意到,当Φ FORMULA-GAME时, Φ TQBF恰好成立,因此该定理直接从定理 8.9 得出。

We can then see that Φ TQBF exactly when φ FORMULA-GAME , so this theorem follows directly from Theorem 8.9.

广义链博弈

Generalized chain game

现在我们知道公式游戏问题是PSPACE完备的,我们可以更容易地证明其他游戏的PSPACE完备性或PSPACE难度。我们将从连锁游戏的概括开始,然后转向国际象棋、跳棋和围棋等游戏。

Now that we know that the formula game problem is PSPACE-complete, we can more easily show PSPACE-completeness or PSPACE-hardness of other games. We will start by generalizing the chain game, and then move on to games such as chess, checkers, and Go.

Chain 是一款儿童游戏,参与者轮流命名世界各地的城市。每个城市的名称必须以先前名称结尾处的字母开头。不允许重复。游戏从选定的起始城市开始,当一名玩家无法继续并失败时结束。例如,如果我们从皮奥里亚开始,下一个城市可能是阿默斯特(因为皮奥里亚以字母 a 结尾,阿默斯特以该字母开头),然后是图森,然后是纳舒亚,依此类推,直到一个玩家可以说出另一个名字并且会输。

Chain is a children's game in which participants take turns naming cities from anywhere in the world. Each city name must begin with the letter that the previous name ended with. No repetitions are allowed. The game begins with a chosen starting city and ends when one player is unable to continue and loses. For example, if we start with Peoria, the next one might be Amherst (since Peoria ends with the letter a, and Amherst begins with that letter), then Tucson, then Nashua, and so on until one player is unable to name another city and loses.

我们可以将这个游戏建模为以城市为顶点的有向图。我们将以符合游戏规则的方式将箭头从一个城市绘制到另一个城市。换句话说,如果名称X以与名称Y开头相同的字母结尾,则图形将包含从城市X到城市Y的边。该图的一个片段如图 8.12 所示。

We can model this game as a directed graph with cities as vertices. We draw arrows from one city to another so that they follow the rules of the game. In other words, the graph will contain an edge from city X to city Y if the name X ends with the same letter that the name Y begins with . A fragment of this graph is shown in Figure 8.12.

8.12

代表连锁游戏的图片段

Figure 8.12

Fragment of a graph representing a game of chain

给定这个图表示,链游戏的规则规定,一个玩家首先选择一个起始顶点,然后玩家依次选择在该图中形成直线路径的顶点。路径是笔直的要求(即,没有顶点被使用多次)对应于城市不能重复自身的规则。无法延长路径的玩家就输了。

Given this graph representation, the rules of the game of chain say that one player begins by choosing a starting vertex, and then players take turns choosing vertices that form a simple path through the graph. The requirement that the path be simple (that no vertex is used more than once) corresponds to the rule that a city cannot be repeated. A player who cannot extend the path loses.

在链游戏的广义版本中,我们假设任何有向图都有一个独特的起始顶点。广义链博弈的一个例子如下图所示。

In the generalized version of the chain game, we assume any directed graph with a distinguished initial vertex. An example of a generalized chain game would be the graph shown in the figure below.

8.13

广义链博弈示例

Figure 8.13

Example of a generalized chain game

假设玩家 I 开始,玩家 II 进行第二步。在这个例子中,玩家 I 有以下获胜策略。它从顶点 1 开始,即突出显示的起始顶点。来自顶点 1 的边仅通向顶点 2 和 3,因此在第一步中,玩家我选择其中一个。假设他选择了顶点 3。现在玩家 II 必须采取行动,但从顶点 3 开始,箭头只能到达 5,所以他必须选择顶点 5。现在玩家 I 从可能性 6、7 和 8 中选择 6。现在玩家 II 必须从顶点 6 开始移动,但唯一的传出边缘指向之前已经访问过的顶点 3。玩家 II 无法移动,因此玩家 I 获胜。

Let's say player I starts, and player II makes the second move. In this example, player I has the following winning strategy. He starts at vertex 1, the distinguished starting vertex. From vertex 1, there are edges leading only to vertices 2 and 3, so player I chooses one of them for his first move. Let's say he chooses vertex 3. Now player II must make a move, but from vertex 3, the arrow only goes to vertex 5, so he must choose vertex 5. Now player I chooses 6 from the possibilities 6, 7, and 8. Now player II must make a move from vertex 6, but the only outgoing edge points to vertex 3, which has already been visited. Player II cannot make a move, so player I wins.

如果我们通过反转顶点 3 和 6 之间的边的方向来改变这个例子,那么玩家 II 将有一个获胜的策略。你能指出来吗?如果玩家 I 像以前一样从顶点 3 开始,那么玩家 II 的反应是移动到 6 并立即获胜,因此玩家 I 唯一的希望就是移动到顶点 2。但是,在这种情况下,玩家 II 的反应是移动到4. 如果玩家 I 现在选择顶点 5,那么玩家 II 通过选择 6 获胜。如果玩家 I 选择 7,那么玩家 II 通过选择 9 获胜。无论玩家 I 做什么,玩家 II 都能找到获胜的方法,即他有一个制胜策略。

If we were to change this example by reversing the direction of the edge between vertices 3 and 6, then Player II would have a winning strategy. Can you tell me what it is? If Player I starts at vertex 3 as before, then Player II responds with a move to 6 and wins immediately, so Player I's only hope is to move to vertex 2. However, in this case, Player II responds with a move to 4. If Player I now chooses vertex 5, then Player II wins by moving to 6. If Player I chooses 7, then Player II wins by choosing 9. No matter what Player I does, Player II can find a way to win, so he has a winning strategy.

在广义链博弈中确定哪个玩家拥有获胜策略的问题是 PSPACE 完备的。让

The problem of determining which player has a winning strategy in a generalized chain game is PSPACE-complete. Let

GG = { G , b :玩家 I 在以起始顶点b为起始点的图G上进行的广义链博弈中具有获胜策略}。

GG = { G , b : player I has a winning strategy in the generalized chain game played on the graph G with starting vertex b }.

定理8.14

Theorem 8.14

GG问题是 PSPACE 完备问题。

The GG problem is PSPACE-complete.

证明的概念 类似于定理 8.9 证明中使用的递归算法使我们能够确定哪个玩家具有获胜策略。该算法在多项式内存中运行,因此GG PSPACE。

Concept of the Proof A recursive algorithm similar to the one used in the proof of Theorem 8.9 allows us to determine which player has a winning strategy. This algorithm operates on polynomial memory, and hence GG PSPACE.

为了证明GG问题是 PSPACE-hard 问题,我们提出了将FORMULA-GAME问题多项式简化为GG 的方法。这种归约将公式博弈转化为广义链博弈图,使得图上的博弈模仿了公式博弈。实际上,广义连锁游戏的玩家实际上是在玩公式游戏的编码版本。

To prove that the GG problem is PSPACE-hard, we present a polynomial reduction of the FORMULA-GAME problem to GG . This reduction transforms the game of the formula into a generalized chain game graph, so that the game of the graph mimics the game of the formula. As a result, players of the generalized chain game actually play a coded version of the game of the formula.

证明 以下算法确定玩家I在广义链博弈的某个实例中是否有获胜策略;换句话说,它解决了GG问题。我们将展示它在多项式内存中的工作原理。

Proof The following algorithm decides whether player I has a winning strategy in a certain instance of the generalized chain game; in other words, it decides the problem GG . We will show that it works in polynomial memory.

M = "对于输入词G , b ,其中G是有向图,b是G的可区分顶点:

M = "For an input word G , b , where G is a directed graph and b is a distinguished vertex of G :

  1. 如果b的出局度为 0,则丢弃,因为玩家 I 立即失败。
  2. If outgoing rank b is 0, discard , as player I loses immediately.
  3. 删除顶点b以及与其相连的所有边,得到新的图G'。
  4. Delete vertex b and all edges connected to it, obtaining a new graph G'.
  5. 对于从顶点b开始的箭头所指向的每个顶点b 1 , b 2 , …, b k ,对于输入词G'b递归地调用M
  6. For each of the vertices b 1 , b 2 , …, b k , to which the arrows from vertex b pointed , recursively invoke M for the input word G' , b i .
  7. 如果机器M在所有这些调用中都达到接受状态,则玩家 II 在原始游戏中具有获胜策略,因此拒绝。否则,玩家 II 没有获胜策略,所以玩家 I 必须有一个,所以接受吧。”
  8. If in all these calls machine M reaches the accepting state, player II has a winning strategy in the original game, so reject . Otherwise player II has no winning strategy, so player I must have one, so accept .

上述算法仅使用内存来存储递归调用的堆栈。每级递归都会向堆栈添加一个顶点,最大级数为m,其中m是G中的顶点数。因此,该算法在线性存储器中工作。

The above algorithm uses memory only to store the stack of recursive calls. Each level of recursion adds a single vertex to the stack, and the maximum number of levels is m , where m is the number of vertices in G . Hence, this algorithm works in linear memory.

为了证明GG问题的 PSPACE 难度,我们将证明FORMULA-GAME问题可以多项式简化为它。这种减少改变了公式

To prove the PSPACE-hardness of the problem GG , we will show that the problem FORMULA-GAME is polynomially reducible to it. This reduction transforms the formula

Φ = x 1 x 2 x 3 Qx k [ Φ ]

Φ = x 1 x 2 x 3 Qx k [ φ ]

在广义链博弈的< G , b >的实例中。为了简单起见,我们假设公式Φ的量词以量词开始和结束,并且两种类型的量词在它们之间交替。通过简单地添加带有未使用的“人工”变量的量词,不满足此假设的公式可以轻松地转换为符合此形式的稍大的公式。我们还假设公式φ是合取范式(参见问题 8.12)。

into an instance G , b of the generalized chain game. For simplicity, we assume that the quantifiers of the formula Φ begin and end with the quantifier , and that the two kinds of quantifiers alternate between them. A formula that does not satisfy this assumption can be easily transformed into a slightly larger one that is consistent with this form by simply adding quantifiers with unused, “artificial” variables. We also assume that the formula φ is in conjunctive normal form (see Problem 8.12).

该简化为链式博弈构建了一个图,其中最优游戏玩法模仿了Φ公式游戏中的最优游戏玩法。连锁游戏中玩家I扮演公式游戏中玩家E的角色,玩家II扮演玩家A的角色。

The reduction constructs a graph for the chain game in which the optimal gameplay mimics the optimal gameplay in the formula game Φ . Player I in the chain game takes the role of player E in the formula game, and player II takes the role of player A .

图G的部分结构如下图所示。游戏从顶点b开始,该顶点位于图G的顶部。下面的b是一系列菱形结构,一个对应于公式φ的每个变量。在我们继续讨论图G的右侧之前,让我们先看一下左侧的游戏玩法。

Part of the structure of G is shown in the figure below. The game starts at vertex b at the top of G . Below b is a sequence of rhombus structures, one for each of the variables in the formula φ . Before we move on to the right side of G , let's look at how the game progresses on the left side.

8.15

模拟公式游戏的链式博弈结构的一部分

Figure 8.15

Part of the structure of a chain game simulating a game with a formula

游戏从顶点b开始。玩家 I 必须选择来自b 的两条边之一。这些边对应于公式游戏开始时变量值的可能选择。左边缘的选择对应于公式游戏中玩家E选择的值TRUE ,而右边缘对应于值FALSE。当玩家 I 选择其中一条边(假设是左边的边)时,玩家 II 就会移动。只有一个可用的传出边,因此这一举动是被迫的。类似地,玩家 I 被迫进行另一次移动,游戏从第二个菱形的上顶点继续。我们再次有两条边可供选择,但这一次的行动由玩家 II 决定。这对应于公式游戏中玩家A的第一步。随着游戏的继续,玩家 I 和 II 选择穿过每个菱形的左侧或右侧路径。

The game begins at vertex b . Player I must choose one of the two edges coming out of b . These edges correspond to the possible choices of the variable value at the beginning of the formula game. The choice of the left edge corresponds to the choice of TRUE by player E in the formula game, and the right edge corresponds to the value FALSE. When player I chooses one of the edges – let's say the left one – player II moves. There is only one outgoing edge available, so this move is forced. Similarly, the next move of player I is forced, and the game continues from the top vertex of the second rhombus. Again, we have a choice of two edges, but this time the move belongs to player II. This corresponds to the first move of player A in the formula game. As the game continues, players I and II choose the left or right path through each rhombus.

经过所有菱形后,路径到达最后一个菱形的底部顶点,这是玩家 I 的移动,因为我们假设最后一个量词是。玩家 I 别无选择,只能移动到图 8.15 中的顶点c,玩家 II 在那里进行另一次移动。

After passing through all the rhombuses, the path reaches the bottom vertex of the last rhombus, and this is player I's move, since we assumed that the last quantifier is . Player I has no choice but to move to vertex c in Figure 8.15, where player II makes the next move.

链式游戏中的这一点对应于公式游戏的结束。所选择的穿过菱形的路径对应于Φ公式的变量的赋值。如果本次评估中公式φ为 TRUE ,则玩家E获胜;如果φ为 FALSE,则下图右侧的结构保证如果玩家E获胜,则玩家 I 获胜,如果玩家A获胜,则玩家 II 获胜。

This point in the chain game corresponds to the end of the formula game. The chosen path through the diamonds corresponds to the assignment of values ​​to the formula variables Φ . If, under this valuation, the formula φ evaluates to TRUE, player E wins; if φ evaluates to FALSE, player A wins. The structure of the right-hand side of the graph in the figure below guarantees that player I can win if player E wins , and that player II can win if player A wins .

8.16

模拟公式博弈的链式博弈全图,其中Φ = x 1 x 2 x k [( x 1 x 2 x 3 ) ( x 2 x 3 ) ( )]

Figure 8.16

The complete graph of the chain game simulating the game with the formula Φ = x 1 x 2 x k [( x 1 x 2 x 3 ) ( x 2 x 3 ) ( )]

在顶点c 处,玩家 II 可以选择与公式φ的子句之一相对应的顶点。然后,玩家 I 可以选择与该子句中的文字相对应的顶点。与非否定文字对应的顶点连接到相应变量的菱形的左侧(对应于 TRUE),对于否定文字和菱形的右侧也是如此,如图 8.16 所示。

At vertex c, player II can choose a vertex corresponding to one of the clauses of the formula φ . Then player I can choose a vertex corresponding to a literal in that clause. The vertices corresponding to unnegated literals are connected to the left (corresponding to the value TRUE) sides of the rhombuses of their corresponding variables, and similarly for negated literals and right sides of the rhombuses, as in Figure 8.16.

如果公式φ为 FALSE,则玩家 II 可以通过选择未履行的条款获胜。玩家 I 选择的任何文字都具有值 FALSE,并连接到尚未玩过的菱形一侧。因此,玩家可以玩到菱形的顶点,但随后玩家 I 无法再进行任何移动并失败。如果公式φ 的计算结果为 TRUE,则玩家 II 选择的每个子句都包含一个计算结果为 TRUE 的文字。玩家 I 在玩家 II 移动后选择这个文字。由于该文字的值为 TRUE,因此它连接到已经玩过的菱形的一侧,因此玩家 II 无法移动并失败。

If the formula φ is FALSE, then player II can win by choosing an unfulfilled clause. Any literal chosen by player I is then FALSE and connected to a side of the rhombus that has not yet been played. Thus, the player can play to a vertex in the rhombus, but then player I can no longer make a move and loses. If the formula φ is TRUE, then each clause that player II chooses contains a literal with the value TRUE. Player I chooses this literal after player II makes a move. Since this literal is TRUE, it is connected to a side of the rhombus that has already been played, so player II cannot make a move and loses.

在定理 8.14 中,我们表明,除非 P = PSPACE,否则不存在用于在广义链博弈中寻找最优博弈的多项式时间算法。我们想对国际象棋等棋盘游戏中最佳游戏的计算复杂性做出类似的主张,但这里有一个困难。正如您所看到的,标准 8 × 8 棋盘上只有有限数量的可能的游戏配置。一般来说,所有这些设置都可以与每个设置的最佳移动一起排列在一个数组中。这样的数组太大,无法容纳在我们的星系中,但它仍然是有限的,因此可以存储在图灵机(甚至是有限状态机!)的控制器中。通过参考该表,这样的机器可以在线性时间内发挥最佳性能。也许将来会找到量化有限问题复杂性的方法。然而,当今已知和使用的方法是渐近的,因此它们只能让我们估计随着问题规模的增加而增加的复杂度,而不能确定任何固定规模的复杂度。尽管如此,我们可以提供一些证据表明,很难计算许多棋盘游戏的最佳游戏玩法,将它们推广到大小为n × n的棋盘。国际象棋、西洋跳棋和围棋的此类泛化已被证明是 PSPACE 困难的,甚至在更高复杂性的类别中也很困难,具体取决于所选泛化的细节。

In Theorem 8.14 we showed that there is no polynomial-time algorithm for finding an optimal game in the generalized chain game unless P = PSPACE. We would like to show similar theorems for the computational complexity of optimal game play in board games such as chess, but there is a difficulty here. As you can see, there can be only a finite number of possible game configurations on a standard 8 × 8 chessboard. In general, all these configurations could be arranged in an array, along with the best move for each one. Such an array would be too large to fit in our galaxy, but it would still be finite, and so could be stored in the controller of a Turing machine (or even a finite state machine!). Such a machine could play optimally in linear time by referring to this array. Perhaps in the future, methods will be found to quantify the complexity of finite problems. However, the methods known and used today are asymptotic, so they only allow us to estimate the rate of increase of complexity with increasing problem size – not to determine the complexity for any fixed size. Nevertheless, we can provide some indication of the difficulty of computing the optimal gameplay of many board games, generalizing them to boards of size n × n . It has been shown that such generalizations for chess, checkers, and go are PSPACE-hard or even hard in higher complexity classes, depending on the details of the chosen generalization.

8.4

L 级和 NL 级

8.4

Classes L and NL

到目前为止,我们只考虑了至少是线性的时间和内存复杂性约束 - 其中f ( n ) 至少为n。我们现在探索更小的、次线性的内存约束。对于时间复杂度来说,次线性约束甚至不足以读取整个输入单词,因此我们不会关心它们。在亚线性内存复杂性的情况下,机器能够读取整个输入字,但没有足够的内存来存储它。为了合理地考虑这种情况,我们需要修改我们的计算模型。

So far, we have considered only those time and memory constraints that are at least linear—those for which f ( n ) is at least n . We now examine smaller, sublinear memory constraints. For time complexity, the sublinear constraints would not be sufficient even for reading the entire input word, so we will not concern ourselves with them. In the case of sublinear memory complexity, the machine is able to read the entire input word but does not have enough memory to store it. To be able to consider this situation sensibly, we need to modify our computational model.

我们将介绍一个带有两个磁带的图灵机:一个只读输入磁带和一个可以写入和读取的工作磁带。在要读取的磁带上,磁头可以识别符号,但不能更改它们。此外,我们还为机器提供了一种检测头部位于输入的左端或右端的方法。该磁头必须保留在包含输入字的磁带部分上。工作磁带可以按通常的方式读写。在计算此类图灵机的内存复杂度时,仅考虑磁带上查看的单元。

We introduce a Turing machine with two tapes: a read-only input tape and a working tape on which both writing and reading are possible. On the reading tape, the head can recognize symbols but cannot change them. We also provide a way for the machine to detect whether the head is at the left or right end of the input data. This head must remain on the part of the tape containing the input word. The working tape can be read and written to in the usual way. Only the cells that are looked up on the working tape are included in the calculation of the memory complexity of this type of Turing machine.

我们可以将只读输入磁带视为 CD-ROM,这是许多个人计算机中用作数据源的设备。这种光盘通常包含的数据比计算机主存储器中可以存储的数据还要多。次线性内存算法允许计算机处理数据,而无需将其全部放入主内存中。

We can think of a read-only input tape as a CD-ROM, a device used as a data source in many personal computers. Such a CD could often contain more data than the computer could store in main memory. Sublinear memory algorithms allow the computer to process data without storing all of it in main memory.

对于至少是线性的内存约束,这个两带图灵机模型等效于标准单带模型(参见练习 8.1)。对于次线性约束,我们将仅使用双带模型。

For memory constraints that are at least linear, this two-tape Turing machine model is equivalent to the standard one-tape model (see Exercise 8.1). For sublinear constraints, we will use only the two-tape model.

定义 8.17

Definition 8.17

L类是对数内存中的确定性图灵机可判定的语言类。换句话说,

The class L is the class of languages ​​decidable by deterministic Turing machines in logarithmic memory. In other words,

L = 空间(log n )。

L = SPACE(log n ).

NL类是一类可由对数内存中的非确定性图灵机判定的语言。换句话说,

The class NL is the class of languages ​​that are decidable by nondeterministic Turing machines in logarithmic memory. In other words,

NL = NSPACE(log n )。

NL = NSPACE(log n ).

我们将重点关注 log n的内存限制,而不是√nlog 2n,原因有几个,这些原因类似于通知多项式时间和内存限制的选择的原因。对数有界内存(我们简称为“对数内存”)足够大,可以解决许多有趣的计算问题,同时还具有有吸引力的数学特性,例如对机器模型选择和输入编码更改的鲁棒性。指向输入字中位置的指针可以用对数内存表示,因此我们可以将对数内存算法视为使用有限数量的指向输入字的指针的算法。

We will focus on the log n memory bound , rather than, for example, n or log 2 n , for several reasons that are analogous to those that underlie the choice of polynomial time and memory bounds. Logarithmically bounded memory (we will simply say "logarithmic memory") is large enough to allow the solution of many interesting computational problems, while also having attractive mathematical properties such as being robust to the choice of the machine model and to changes in the encoding of the input data. Pointers to locations in the input word can be represented in logarithmic memory, so we can think of algorithms with logarithmic memory as algorithms that use a finite number of pointers to the input word.

8.18

Example 8.18

语言 A = {0 k 1 k : k ≥ 0} 属于L类。在第 275 页的 7.1 节中,我们描述了一种图灵机,它通过来回遍历输入单词并从中成对地去除 0 和 1 来解析语言A。该算法使用线性内存来存储已绘制的项目,但可以修改为仅使用对数内存。

The language A = {0 k 1 k : k ≥ 0} belongs to the class L . In Section 7.1 on page 275, we described a Turing machine that resolves the language A by looping back and forth through the input word and striking out pairs of zeros and ones. This algorithm uses linear memory to store the entries that have been struck out, but it can be modified to use only logarithmic memory.

语言A 的对数图灵机无法在输入磁带上绘制匹配的 0 和 1,因为该磁带是只读的。相反,机器会计算零的数量,并单独计算传送带上二进制零的数量。所需的内存仅限于两个计数器使用的内存。使用二进制存储,每个计数器只需要对数内存,因此算法在O (log n ) 内存中运行。因此A L。

A Turing machine with logarithmic storage for A cannot strike out matching zeros and ones on the input tape, because that tape is read-only. Instead, the machine counts the number of zeros and, separately, the number of binary zeros on the work tape. The memory needed is limited to that used by the two counters. In binary storage, each counter requires only logarithmic storage, so the algorithm runs in O (log n ) memory. Hence, A L .

8.19

Example 8.19

让我们回忆一下语言

Let's recall the language

PATH = { G , s , t G是一个有向图,其中存在从顶点st的有向路径}

PATH = { G , s , t : G is a directed graph such that there is a directed path from vertex s to t }

定义见第 7.2 节。定理 7.14 表明PATH问题属于 P 类,但其中所示的算法使用线性内存。我们不知道是否存在适用于对数内存的PATH问题的确定性解决方案,但有一种已知的适用于对数内存的非确定性算法。

defined in Section 7.2. Theorem 7.14 shows that the PATH problem belongs to the class P, but the algorithm shown there uses linear memory. We do not know whether there is a deterministic solution to the PATH problem that runs in logarithmic memory, but there is a known nondeterministic algorithm that runs in logarithmic memory.

决定PATH 的非确定性对数内存图灵机从顶点s开始,并不确定地猜测通向t 的路径的顶点。在每个步骤中,机器仅具有构建磁带上的当前顶点,而不是整个路径(这将超出对数内存限制)。机器不确定地从当前顶点指向的顶点中选择下一个顶点。它重复此操作,直到到达顶点t,并在采取m步未到达顶点t时接受拒绝,其中m是图中的顶点数。正如你所看到的,PATH问题属于NL类。

A nondeterministic Turing machine operating in logarithmic memory deciding PATH starts at vertex s and nondeterministically guesses the vertices of the path to t . At each step, the machine has only the current vertex on its work tape, not the entire path (which would exceed the limit of logarithmic memory). The machine nondeterministically chooses the next vertex from those pointed to by the current vertex. It repeats this action until it reaches vertex t and accepts or rejects after it has taken m steps without reaching vertex t , where m is the number of vertices in the graph. As you can see, the PATH problem belongs to the class NL.

前面提到的任何在内存f ( n ) 中运行的图灵机运行时间为 2 O ( f ( n ))的说法对于非常小的内存限制来说是不正确的。例如,使用O (1)(即常数)内存的图灵机可以运行n步。为了获得每个内存约束f ( n ) 的运行时界限,我们需要以下定义。

The theorem shown earlier that any Turing machine running on memory f ( n ) runs in time 2O ( f ( n )) is not true for very small memory constraints. For example, a Turing machine using O (1) (i.e. constant) memory can run for n steps. To obtain the running time bound that will hold for any memory constraint f ( n ), we need the following definition.

定义 8.20

Definition 8.20

如果M是具有单独的只读输入带的图灵机,并且字w是输入字,则M对于字w的配置是状态、工作带的内容以及两个磁头的位置。输入字w不是字w的M配置的一部分。

If M is a Turing machine with a separate read-only input tape and word w is an input word, then the configuration of M for word w is the state, the contents of the working tape, and the positions of the two heads. Input word w is not part of the configuration of M for word w .

如果机器M在内存f ( n ) 中运行,并且w是长度为n的输入字,则 M对于w的配置数量为n 2 O( f ( n ))。为了解释这个结果,假设机器Mc 个状态和g 个磁带符号。草稿带上可以出现的单词数是g f ( n )。输入头可以位于n个位置之一,传送带头可以位于f ( n ) 个位置之一。因此,机器M对字w的配置总数,即机器M对字w的运行时间上限为 cnf( n )g f ( n ),或n 2 O( f ( n ))

If a machine M operates on memory f ( n ) and w is an input word of length n , the number of configurations of M for w is n 2 O( f ( n )) . To explain this result, suppose that the machine M has c states and g tape symbols. The number of words that can appear on the work tape is g f ( n ) . The input head can be in one of n positions, and the work tape head can be in one of f ( n ) positions. Hence the total number of configurations of machine M for word w , that is, the upper bound on the operating time of machine M for word w , is cnf( n )g f ( n ) , that is, n 2 O( f ( n )) .

我们几乎只关注内存约束f ( n ),其至少为 log n。我们之前的说法是,对于此类约束,机器的时间复杂度相对于其内存复杂度至多是指数级的,因为当f ( n时n 2 O( f ( n ))等于 2 O( f ( n )) ) ≥ log n

We focus almost exclusively on the memory bounds of f ( n ) that are at least log n . Our earlier theorem that the time complexity of a machine is at most exponential with respect to its memory complexity remains valid for such bounds, since n 2 O( f ( n )) is equal to 2 O( f ( n )) when f ( n ) ≥ log n .

回想一下萨维奇定理,我们在该定理中证明,我们可以通过仅通过将f ( n ) ≥ n的假设平方来增加 f(n)的内存复杂性,从而将非确定性图灵机转换为确定性图灵机。我们可以扩展 Savitch 定理,使其也适用于次线性内存约束,最高可达f ( n ) ≥ log n。该证明与我们在第 334 页上提出的原始证明相同,只是我们现在使用带有只读输入磁带的图灵机,并且我们将参考机器N的配置而不是参考机器N的配置词w。存储机器N对于w的配置使用内存 log( n 2 O( f ( n )) ) = log n + O ( f ( n ))。如果f ( n ) ≥ log n,则使用的内存为O ( f ( n )) 并且证明的其余部分保持不变。

Recall Savitch's theorem, in which we showed that we can transform a nondeterministic Turing machine into a deterministic one by increasing the space complexity of f ( n ) merely by squaring it, provided that f ( n ) ≥ n . We can extend Savitch's theorem to hold for sublinear space constraints, up to f ( n ) ≥ log n . The proof is identical to the original one, which we gave on page 334, except that we now use Turing machines with a read-only input tape, and instead of referring to the configuration of N , we refer to the configuration of N for word w . Storing the configuration of N for w uses the memory log( n 2 O( f ( n )) ) = log n + O ( f ( n )). If f ( n ) ≥ log n , then the memory usage is O ( f ( n )) and the rest of the proof remains unchanged.

8.5

NL-完整性

8.5

NL-completeness

正如我们在例 8.19 中提到的,已知PATH问题属于 NL 类,但不知道它是否属于 L 类。有人相信PATH不属于 L 类,但不知道如何证明这一点假设。事实上,没有任何属于 NL 类的已知问题已被证明不适合 L 类。与是否 P = NP 的问题类似,因此我们有是否 L = NL 的问题。

As we mentioned in Example 8.19, it is known that the problem PATH is of class NL, but it is not known whether it is of class L. It is believed that PATH is not of class L, but it is not known how to prove this conjecture. In fact, there is no known problem of class NL for which it has been proven that it is not of class L. Analogous to the question whether P = NP, we have the question whether L = NL.

回答这个问题的一个步骤是确定几种 NL 完整语言。与其他复杂性类别的完备性一样,NL 完备语言是在某种意义上是 NL 类别中最难的语言的示例。如果 L 类和 NL 类不同,则 NL 完备语言不能属于 L 类。

A step toward answering this question is to point to some NL-complete languages. As with completeness for other complexity classes, NL-complete languages ​​are examples of languages ​​that are in some sense the most difficult languages ​​in the NL class. If the classes L and NL are different, then no NL-complete language can be in the L class.

与前面的完整性定义一样,我们将 NL 完备语言定义为属于 NL 类的语言,属于 NL 类的任何其他语言都可以归约到该语言。然而,这一次,我们不会使用多项式时间的缩减,因为正如我们将看到的,所有属于 NL 类的问题都可以在多项式时间内解决。因此,除了ØΣ *之外,属于 NL 类的任何两个问题都是多项式时间可彼此约简的(参见第 337 页上的 PSPACE 完整性定义所伴随的多项式时间约简性的讨论)。因此,多项式时间的可约性太强,无法区分属于 NL 类的问题。相反,我们将使用一种称为对数内存缩减的新型缩减。

As in the previous definitions of completeness, we define an NL-complete language as a language of the class NL to which any other language of the class NL can be reduced. This time, however, we will not use polynomial-time reduction, since, as we will see, all problems of the class NL are solvable in polynomial time. Thus, any two problems of the class NL except Ø and Σ * are polynomial-time reducible to each other (see the discussion of polynomial-time reducibility accompanying the definition of PSPACE-completeness on page 337). Polynomial-time reducibility is therefore too strong to allow us to distinguish problems of the class NL. Instead, we will use a new type of reduction called logarithmic-space reduction .

定义 8.21

Definition 8.21

在对数存储器中运行的传感器是具有只读输入磁带、只写输出磁带和读写工作磁带的图灵机。输出磁带上的磁头无法向左移动,因此无法读取其写入的符号。工作带可以包含O (log n ) 个符号。在对数存储器M中运行的传感器计算函数f : Σ * Σ *,其中f ( w ) 是当机器M以输入磁带上的单词w开始时终止后输出磁带上的单词。函数f称为对数记忆可计算函数。语言A在对数内存还原为语言B ,如果A可通过使用对数内存中可计算的函数f映射到B来还原,则我们将其写为AL B 。

A transducer operating in logarithmic memory is a Turing machine with a read-only input tape, a write-only output tape, and a read-write working tape. The head on the output tape cannot move to the left, so it cannot read the symbols it has written. The working tape can contain O (log n ) symbols. A transducer operating in logarithmic memory M computes the function f : Σ * Σ *, where f ( w ) is the word on the output tape after M finishes when it starts working with word w on the input tape. The function f is called a function computable in logarithmic memory . A language A is reducible in logarithmic memory to B , which we write AL B , if A is reducible by mapping to B using a function f computable in logarithmic memory.

现在我们可以定义NL完备性的概念了。

Now we can define the notion of NL-completeness.

定义 8.22

Definition 8.22

语言BNL 完备的,如果

A language B is NL-complete if

  1. B NL,
  2. B NL,
  3. 任何属于 NL 类的语言A都可以对数简化为语言B。
  4. every language A belonging to class NL is reducible in logarithmic memory to language B .

如果某种语言可以对数约简为我们已知属于 L 类的另一种语言,那么原始语言也属于 L 类,正如我们将在下面的定理中所示。

If a language is reducible in logarithmic memory to another language which we already know to be of the class L, then the original language is also of the class L, as we will show in the following theorem.

定理8.23

Theorem 8.23

如果AL BB L,则A L。

If A ≤L B and B L, then A L.

证明 在这个证明中使用模仿定理 7.31 证明的方法可能很诱人,其中我们展示了多项式时间可约性的类似结果。,语言A的对数记忆算法首先使用对数约简f将其输入单词w转换为f ( w ) ,然后应用语言B的对数记忆算法。然而,存储字符串f ( w ) 所需的内存可能太大,无法满足对数内存限制。所以我们需要改变这种做法。

Proof It may be tempting to use an approach for this proof that mimics the proof of Theorem 7.31, where we showed an analogous result for polynomial-time reducibility. In such an approach, the logarithmic memory algorithm for language A first transforms its input w into f ( w ) using a reduction in logarithmic memory f , and then applies the logarithmic memory algorithm to language B . However, the memory required to store the string f ( w ) may turn out to be too large to fit the logarithmic memory limit. So we need to change this approach.

相反,语言A的M A 机器计算单词f ( w ) 的各个符号,因为语言B的M B机器需要这些符号。在这个模拟中,M A记住机器M B的输入头对于单词f ( w )的位置。在机器M B的每次移动中,机器M A从头开始​​计算单词w的函数f ,并跳过除单词f ( w ) 中所需位置之外的所有返回符号。这可能需要重新计算单词f ( w ) 的某些部分,因此从时间复杂度的角度来看效率很低。这种方法的优点是任何时候只需要存储一个字符号f ( w ),这样就节省了内存。

Instead, machine M A for language A computes individual symbols of word f ( w ) as they are needed by machine M B for language B . In this simulation, M A remembers the position of machine M B 's input head for word f ( w ). On each move of machine M B , machine M A starts computing the function f for word w from the beginning and omits all the returned symbols except the one for the desired position in word f ( w ). This operation may require recomputing some parts of word f ( w ) and is therefore inefficient from a time-complexity point of view. The advantage of this method is that at any given time only one symbol of word f ( w ) needs to be stored , so we spend time saving memory.

结论 8.24

Motion 8.24

如果任何 NL 完备语言属于 L 类,则 L = NL。

If any NL-complete language belongs to the class L, then L = NL.

图搜索

Graph Search

定理8.25

Theorem 8.25

PATH问题是 NL 完备问题。

The PATH problem is NL-complete.

证明的概念 在例8.19中,我们证明了PATH问题是NL问题,因此我们只需要证明它是NL-hard问题即可。换句话说,我们需要证明属于 NL 类的每种语言A都可以对数内存简化为PATH问题。

Concept of the Proof In Example 8.19 we showed that the PATH problem is a member of the class NL, so we only need to show that it is NL-hard. In other words, we need to show that every language A that is a member of the class NL is reducible in logarithmic space to the PATH problem .

从语言APATH的对数内存减少背后的想法是构建一个图,表示语言A的非确定性图灵机的计算,在对数内存中运行。这种简化将单词w映射到一个图,该图的顶点对应于输入单词w的非确定性图灵机的配置。如果第一个顶点对应的配置可以在本机的一步中转到第二个顶点,则一个顶点指向另一个顶点。如果从对应于初始配置的顶点到对应于接受配置的顶点存在任何路径,则机器接受单词。

The idea behind the logarithmic memory reduction from language A to PATH is to construct a graph representing the computation of a nondeterministic Turing machine for language A , operating on logarithmic memory. This reduction maps a word w to a graph whose vertices correspond to the configurations of a nondeterministic Turing machine for input word w . One vertex points to another if the configuration corresponding to the first can be traversed to the second in a single machine step. The machine accepts the word w , if there is some path from the vertex corresponding to the initial configuration to the vertex corresponding to the accepting configuration.

证明 我们将展示如何构造属于 NL 类的任何语言A 的对数内存约简到PATH问题。令M为内存O (log n )中的 NTM 解析语言 A。给定一个输入单词w,我们在对数内存中构造编码< G , s , t >,其中G是一个包含从顶点st的路径的有向图,当且仅当机器M接受单词w时。

Proof We show how to construct a logarithmic-memory reduction of any language A of class NL to the problem PATH . Let M be an O(log n ) NTM that resolves A in O (log) memory. Given an input word w , we construct a logarithmic-memory encodingG , s , t , where G is a directed graph containing a path from vertex s to t if and only if M accepts word w .

图G的顶点是机器M对于w的配置。如果c 2是从配置c 1开始的机器M的可能的下一个配置之一,则对 ( c 1 , c 2 )(其中c 1c 2是M对于w的配置)是图G的边。更准确地说,如果机器的转换函数M显示从配置c 1中描述的状态,连同输入和工作磁头下的磁带符号,可以将机器转换到所描述的状态和磁头位置,则存在这样的边缘在配置c 2中。顶点s是机器M对于单词w的初始配置。机器M被修改为只有一个唯一的接受配置,我们将该配置表示为顶点t

The vertices of the graph G are configurations of the machine M for w . The pair ( c 1 , c 2 ), where c 1 and c 2 are configurations of M for w , is an edge of G , if c 2 is one of the possible next configurations of the machine M starting in configuration c 1 . More precisely, such an edge exists if the transition function of the machine M implies that from the state described by configuration c 1 , together with the tape symbols under the input and work heads, it is possible for the machine to transition to the state and head positions described by configuration c 2 . Vertex s is the initial configuration of the machine M for word w . The machine M is modified so that it has only one, unique accepting configuration, and we designate this configuration as vertex t .

这种映射将语言A简化为PATH,因为每当M接受其输入字时,就会有一条接受计算路径,该路径在图G中对应于从初始配置s到接受配置t的路径。相反,如果在图G中存在从顶点st的某个路径,则当针对输入词w运行M时,某个计算路径会接受,因此M接受w

This mapping reduces language A to PATH , since whenever M accepts its input word, then there is an accepting computation path that corresponds in the graph G to the path from the initial configuration s to the accepting configuration t . Conversely, if in the graph G there is some path from vertex s to t , then some computation path accepts when M is run for input word w , and therefore M accepts w .

为了证明这种简化在对数存储器中起作用,我们将展示一个在对数存储器中运行的传感器,它为输入词w打印< G , s , t >。我们将通过枚举图G的顶点和边来描述图G。枚举顶点很简单,因为每个顶点都是机器Mw的配置,并且可以在大小为c log n的内存中表示为某个常数c。传感器按顺序遍历所有可能的长度为c log n的单词,检查该单词是否是M对于w的有效配置,然后打印出通过测试的单词。边缘的计算方式类似。为了检查是否可以从机器M的字w的配置c 1转到配置c 2 ,对数存储器就足够了,因为转换器只需要检查c 1中给出的磁头位置处磁带的当前内容确定机器M的转移函数是否可以给出结果配置c 2。传感器尝试所有对 ( c 1 , c 2 ) 以确定哪些符合G的边缘。满足条件的内容将添加到输出磁带中。

To show that this reduction works in logarithmic memory, we show a converter operating in logarithmic memory that prints G , s , t for an input word w . We describe the graph G by computing its vertices and edges. Computing the vertices is straightforward, since each vertex is a configuration of M for w and can be represented in memory of size c log n for some constant c . The converter successively traverses all possible words of length c log n , tests whether a given word is a valid configuration of M for w , and then prints out those that pass this test. The edges are computed in a similar way. To check whether it is possible to go from configuration c 1 of M for word w to configuration c 2 , all that is needed is logarithmic memory, since the converter need only check the current contents of the tape at the head positions given in c 1 to determine whether the transition function of M can produce configuration c 2 . The transducer tries all pairs ( c 1 , c 2 ) in turn to determine which qualify as edges of the graph G . Those that satisfy the condition are added to the output tape.

定理 8.25 的直接结果是以下结论,该结论表明 NL 类是 P 类的子集。

An immediate result of Theorem 8.25 is the following corollary, which states that the class NL is a subset of the class P.

结论 8.26

Motion 8.26

NL P

NL P.

定理 8.25 的证明 表明,任何属于 NL 类的语言都可以对数内存简化为PATH问题。回想一下,使用内存f ( n )的图灵机在时间n 2 O ( f ( n ))中运行,因此在对数内存中运行的归约函数也以多项式时间运行。因此,任何属于 NL 类的语言都可以通过多项式时间简化为PATH问题,而 PATH 问题又属于 P 类,如我们在定理 7.14 中所示。我们知道,任何能在多项式时间内约简为属于P的语言的语言也属于P,这就完成了证明。

Proof Theorem 8.25 shows that any language of class NL is reducible in logarithmic memory to the problem PATH . Recall that a Turing machine that uses memory f ( n ) runs in time n 2 O( f ( n )) , so a reduction function that runs in logarithmic memory also runs in polynomial time. Thus, any language of class NL is reducible in polynomial time to the problem PATH , which in turn is a language of class P, as we showed in Theorem 7.14. We know that any language that is reducible in polynomial time to a language of P also belongs to P, which completes the proof.

尽管对数内存中的约简性似乎非常有限,但它是复杂性理论中使用的大多数约简的正确选择,因为此类函数通常计算简单。例如,在定理 8.9 中,我们证明每个 PSPACE 问题都可以多项式时间简化为TQBF问题。这些归约中计算的公式包含许多重复部分,并且可以使用对数内存进行计算,因此我们可以得出结论,TQBF问题相对于对数内存的归约而言是 PSPACE 完备的。这是一个非常重要的结论,因为推论 9.6 表明 NL  ⊆  PSPACE。从这种遏制和对数记忆中显示的可归约性,我们可以得出结论:TQBF NL。

Although reducibility in logarithmic memory seems very restrictive, it is the right choice for most reductions used in complexity theory, since such functions are usually computationally simple. For example, in Theorem 8.9 we showed that every problem of the class PSPACE is reducible in polynomial time to a TQBF problem . The formulas evaluated in these reductions contain many repeated fragments and can be computed using logarithmic memory, so we can conclude that the TQBF problem is PSPACE-complete with respect to the reduction in logarithmic memory. This is a very important conclusion, since Corollary 9.6 shows that NL  ⊆  PSPACE. From this inclusion and the shown reducibility in logarithmic memory, we can conclude that TQBF NL.

8.6

NL 级等于 coNL 级

8.6

Class NL equals class coNL

本节包含有关不同类别计算复杂性之间关系的最令人惊讶的结果之一。 NP 和 coNP 类别通常被认为是彼此不同的。乍一看,NL 和 coNL 级别应该也是如此。正如我们稍后将证明的那样,NL 类等于 coNL 类,这一事实表明我们的计算直觉仍然存在许多差距。

This section contains one of the most surprising results concerning the relationship between different classes of computational complexity. The classes NP and coNP are generally considered to be different from each other. At first glance, the same should hold for the classes NL and coNL. The fact that the class NL equals the class coNL, as we will prove in a moment, shows that our intuitions about computation still contain many gaps.

定理8.27

Theorem 8.27

NL=coNL。

NL = coNL.

证明的概念 我们将证明PATH问题属于 NL 类,从而证明属于 coNL 类的每个问题也属于 NL 类,因为PATH问题是 NL 完备的。当输入图G不包含从顶点s到顶点t 的路径时,我们针对PATH问题提出的 NL M类算法。

Concept of the Proof We will show that the PATH problem belongs to the class NL, thereby showing that every problem belonging to the class coNL also belongs to the class NL, since the PATH problem is NL-complete. The NL algorithm M , which we will present for the PATH problem , must contain an accept computation whenever the input graph G does not contain a path from vertex s to vertex t .

让我们先解决更简单的问题。令c为图G中从顶点s可到达的顶点数。假设c作为机器M的输入,我们将展示如何使用此信息来解决PATH问题。稍后我们将展示如何计算c的值。

We first solve an easier problem. Let c be the number of vertices of the graph G that are reachable from vertex s . Suppose that c is given as input to machine M and we show how to use this information to solve the PATH problem . Later we show how to compute the value of c .

给定Gstc,机器M 的工作方式如下。它顺序遍历G的所有m 个顶点,并不确定地猜测给定顶点是否可以从顶点s到达。每当机器M猜测顶点u可达时,它会尝试通过猜测从顶点su的长度不超过m的路径来验证该假设。如果这个假设未能得到证实,机器就会丢弃这个非确定性计算路径上的输入。此外,如果检查的顶点是t,机器也会拒绝它。机器M计算已验证可达的顶点数。当机器在某个计算路径 上遍历完G 的所有顶点时,它会检查被验证从顶点s可达的顶点数是否等于c,如果不等于则丢弃它。否则该计算路径接受。

Given G , s , t , and c , machine M operates as follows. It traverses all m vertices of G in turn and nondeterministically guesses whether a given vertex is reachable from vertex s . Whenever machine M guesses that vertex u is reachable, it attempts to verify this conjecture by guessing a path of length no longer than m from vertex s to u . If it fails to confirm this conjecture, the machine rejects the entry on this nondeterministic computational path. In addition, if the vertex being checked is t , then the machine also rejects it. Machine M counts the number of vertices that it has verified as reachable. Whenever the machine has traversed all the vertices of G on some computational path , it checks whether the number of vertices verified as reachable from vertex s is equal to c , and rejects if it is not. Otherwise, this computational path is accepting.

换句话说,机器M不确定地精确选择从顶点s可到达的c 个顶点,使得顶点t不在其中,并通过猜测通向每个顶点的路径来检查每个顶点是否可从s到达。机器M知道其余顶点(包括t)不可到达,因此它可以接受输入。

In other words, machine M nondeterministically chooses exactly c vertices reachable from vertex s , such that vertex t is not among them , and checks that each of them is reachable from s by guessing a path to it. Machine M knows that the remaining vertices, including t , are not reachable, so it can accept the input.

现在我们将展示如何计算c ,它是从顶点s可到达的顶点数 。我们将描述在对数存储器中运行的非确定性过程,其中至少一个计算路径获得正确的c值,并且所有其他计算路径最终丢弃输入。

We now show how to compute c , the number of vertices reachable from vertex  s . We describe a nondeterministic procedure operating in logarithmic memory in which at least one computation path produces the correct value of c , and all other computation paths terminate by rejecting the input.

对于从 0 到m的每个i ,我们将A i定义为距离i或小于s的顶点集(即,距离顶点s的路径长度最多为i 的顶点)。所以我们有A 0 = { s },每个集合A iA i +1,并且A m是从s可到达的所有顶点的集合。令c i为集合A i中的顶点数。我们现在将描述从c i计算c i +1的过程。重复此过程可得出所需值c = cm

For each i from 0 to m, we define A i to be the set of vertices that are at distance i or less than s (that is, for which there is a path of length at most i from vertex s ). So we have A 0 = { s }, each set A i A i +1 , and A m is the set of all vertices reachable from s . Let c i be the number of vertices in A i . We now describe a procedure that computes c i +1 from c i . Repeating this procedure yields the desired value c = c m .

我们将使用与前面介绍的类似的想法从c i计算c i +1的值。该算法遍历图G的所有顶点,检查它们是否属于集合A+1,并计算答案为正的顶点。

We calculate the value of c i +1 from c i using an idea similar to the one presented earlier. The algorithm runs through all the vertices of the graph G , checking whether each of them belongs to the set A i +1 and counting the vertices for which the answer is positive.

为了确定顶点v是否属于集合A i +1 ,我们将使用内部循环遍历G的所有顶点,在其中猜测给定顶点是否属于A i。我们将通过猜测来自顶点s的长度最多为i的路径来验证每个正假设。对于每个顶点u,我们验证它属于集合A i,算法检查 (u, v ) 是否是图G的边。如果存在这样的边,则v属于A+1。此外,我们还计算了属于A i的验证为肯定的顶点数量。在内循环结束时,如果集合A i的已验证元素总数不等于c i,则意味着我们还没有找到A i的所有顶点,因此我们拒绝该计算路径。如果分子是c i,而我们还不能证明顶点v属于A i +1,那么我们可以得出结论,该顶点不属于A i +1。这样我们就可以在外循环中到达下一个顶点v 。

To determine whether vertex v belongs to the set A i +1 , we will use an inner loop running through all vertices of G , in which we guess whether a given vertex belongs to A i . We will verify each positive hypothesis by guessing a path of length at most i from vertex s . For each vertex u , for which we verify membership in the set A i , the algorithm checks whether (u, v ) is an edge of the graph G . If there is such an edge, then v belongs to A i +1 . Additionally, we count the number of vertices for which the verification of membership in A i was positive. At the end of the inner loop, if the total number of verified elements of the set A i is not equal to c i , it means that we have not found all the vertices of A i , so we reject this path of computation. If the numerator is equal to c i and we have not yet been able to prove that vertex v belongs to A i +1 , then we can conclude that this vertex does not belong to A i +1 . We can therefore move on to the next vertex v in the outer loop.

证明 以下是PATH问题的算法。设m为图G的顶点数。

Proof The following is an algorithm for the PATH problem . Let m be the number of vertices of the graph G .

M = "对于输入词G , s , t :

M = "For input word G , s , t :

  1. c 0 = 1。A 10 = { s } 包含 1 个顶点1
  2. Let c 0 = 1. A 0 = { s } contains 1 vertex
  3. 对于i = 0 到m − 1:从c i1计算c i +11
  4. For i = 0 to m − 1: Calculating c i +1 from c i
  5. c i +1 = 1。c 1i +1统计顶点A i +1数量1
  6. Let c i +1 = 1. c i +1 counts the vertices of A i +1
  7. 对于属于G的每个顶点v s:检查v A+1是否1 1
  8. For each vertex v s belonging to G : check if v A and +1
  9. d = 0。1在变量d中,我们计算元素A的数量,然后再次计算1
  10. Let d = 0. in variable d we count the elements of A again and
  11. 对于属于G的每个顶点 u :1检查是否 u A i1
  12. For each vertex u belonging to G : check if u A and
  13. 不确定地选择是执行还是跳过以下步骤:
  14. Nondeterministically choose whether to perform or skip the following steps:
  15. 非确定性地从顶点s中 选择一条长度至多为i的路径,如果它未在顶点 u 处结束,则丢弃该路径。
  16. Nondeterministically choose a path of length at most i from vertex s and reject if it does not end at vertex u.
  17. 增量D.1我们验证了 u A i1
  18. Increment d . we have verified that u A and
  19. 如果 (u, v ) 是G的边,则递增c+1并使用新顶点v转到步骤 5 。1我们验证了v A+11
  20. If (u, v ) is an edge of graph G , increment c i +1 and go to step 5 with new vertex v . we have verified that v A i +1
  21. 如果d c i则拒绝1检查我们是否找到所有顶点A i1
  22. If d c and , reject . the check that we have found all the vertices of A and
  23. d = 0。1cm已知;在变量d中,我们再次计算A m的元素1
  24. Let d = 0. c m is already known; in variable d we count again the elements of A m
  25. 对于属于G的每个顶点 u :1检查是否 u A m1
  26. For each vertex u belonging to G : check if u A m
  27. 不确定地,完成或跳过后续步骤:
  28. Nondeterministically either execute or skip the following steps:
  29. 非确定性地从顶点s开始选择一条长度至多为m的 路径,如果该路径未在顶点 u 处结束,则丢弃该路径。
  30. Nondeterministically choose a path from vertex s of length at most m and reject if it does not end at vertex u.
  31. 如果 u = t,则拒绝。我们找到了从顶点st 的1路径1
  32. If u = t , discard . we found a path from vertex s to t
  33. 增量D.1我们验证了 u A m1
  34. Increment d . we have verified that u A m
  35. 如果d cm拒绝1检查我们是否找到了所有顶点A m1否则接受'.
  36. If d c m , reject . checking that we have found all vertices A m Otherwise accept ”.

在每个时刻,这个算法只需要记住值m、 u 、vc ic i +1di和一个指向路径开头的指针。因此它在对数存储器中工作。 (请注意,M算法也将接受错误构造的输入单词。)

At any point, this algorithm only needs to store the values ​​m , u, v , c i , c i +1 , d , i and a pointer to the beginning of the path. It therefore operates in logarithmic memory. (Note that algorithm M will also accept incorrectly formed input words.)

我们目前对不同复杂性类别之间关系的了解可以总结如下:

Our current knowledge about the relationships between different complexity classes can be summarized as follows:

L NL = coNL P NP PSPACE。

L NL = coNL P NP PSPACE.

我们不知道这些包含中哪一个是正确的,尽管我们将在推论 9.6 中证明 NL PSPACE。因此,必须满足 coNL P 或 P PSPACE,但我们不知道是哪一个!大多数研究人员认为上述所有序列都是正确的。

We do not know which of these inclusions are proper, although we will show in Corollary 9.6 that NL PSPACE. Consequently, either coNL P or P PSPACE must hold, but we do not know which! Most researchers believe that all the inclusions in the above sequence are proper.

练习

Exercises

8.1 证明对于任何函数f : N R +,其中f ( n ) ≥ n ,无论我们是否使用单带图灵机模型定义它,内存复杂度类 SPACE( f ( n )) 都是相同的,或具有两个磁带的型号,其中包括一个只读输入。

8.1 Show that for any function f : N R + , where f ( n ) ≥ n , the space complexity class SPACE( f ( n )) is the same whether we define it using a single-tape Turing machine model or a two-tape model with one input read-only.

8.2 考虑标准井字游戏中的以下游戏状态。

8.2 Consider the following state of play in a standard game of tic-tac-toe.

我们假设下一步是玩家×。描述该玩家的制胜策略。 (回想一下,获胜策略不仅是在当前位置可以采取的最佳行动。它还包括玩家必须根据对手的下一步行动采取的所有行动,以便无论对手采取什么行动,才能获胜。 )

Suppose the next move is for player ×. Describe a winning strategy for this player. (Recall that a winning strategy is not just the best move that can be made in the current position. It also includes all the moves that this player must make in response to his opponent’s next moves in order to win, no matter what moves his opponent makes.)

8.3 考虑下面的广义链游戏,其中起始顶点是由来自“无处”的箭头指示的顶点。玩家 I 有制胜策略吗?或者也许是玩家二号?证明你的答案合理。

8.3 Consider the following generalized chain game, where the starting vertex is the one indicated by the arrow coming "from nowhere". Does player I have a winning strategy? Or maybe player II? Justify your answer.

8.4 证明 PSPACE 类对于求和、求补和星号运算是封闭的。

8.4 Show that the class PSPACE is closed under the union, complement, and asterisk operations.

A 8.5 证明A DFA L。

A 8.5 Prove that A DFA L.

8.6 证明任何 PSPACE 困难语言也是 NP 困难语言。

8.6 Prove that any PSPACE-hard language is also NP-hard.

A 8.7 证明 NL 类对于并集、串联和星号运算是闭集。

A 8.7 Prove that the class NL is closed under the union, concatenation, and asterisk operations.

任务

Tasks

8.8EQ REX = { R , S R和 S 是等价的正则表达式}。证明EQ REX PSPACE。

8.8 Let EQ REX = { R , S : R and S are equivalent regular expressions}. Prove that EQ REX PSPACE.

8.9 梯子是一系列单词s 1 , s 2 , …, sk 其中每个单词与前一个单词仅相差一个字符。例如,以下英语单词序列是一个梯子,以“head”开头,以“free”结尾:

8.9 A ladder is a sequence of words s 1 , s 2 , …, s k , in which each word differs from the preceding one by exactly one character. For example, the following sequence of English words is a ladder, starting with "head" and ending with "free":

头、听、近、恐惧、熊、啤酒、鹿、行为、饲料、脚、烦恼、自由。

head, hear, near, fear, bear, beer, deer, deed, feed, feet, fret, free.

LADDER DFA = { M , s , t M是一个确定性有限自动机,L( M ) 包含一个从s开始到t结束的单词梯子}。证明LADDER DFA问题属于PSPACE类。

Let LADDER DFA = { M , s , t : M is a deterministic finite automaton and L( M ) contains a ladder of words starting at s and ending with t }. Show that the LADDER DFA problem belongs to the class PSPACE.

8.10在日本围棋 游戏中,两名棋手“ X ”和“O”交替在 19 × 19 的网格上放置标记。第一个将五个符号排列成行、列或对角线的玩家获胜。考虑将此游戏推广到n × n棋盘。让

8.10 In the Japanese game of go-moku, two players " X " and "O" alternately place their marks on a 19 × 19 grid. The first player to place five of his marks in a row, column, or diagonal in succession wins. Consider a generalization of this game to an n × n board . Let

GM = { <B> B是广义围棋中的位置,玩家“ X ”有获胜策略}。

GM = { B : B is a position in generalized go-moku where player " X " has a winning strategy}.

我们所说的位置是指棋盘上已经放置了某些标志,这可能发生在游戏的中间阶段,并指示哪个玩家将采取下一步行动。证明GM PSPACE。

By position we mean a board with some signs already placed on it, such as may occur in the middle phase of the game, together with an indication of which player is to make the next move. Prove that GM PSPACE.

8.11 证明如果每种 NP 困难语言也是 PSPACE 困难语言,则 PSPACE = NP。

8.11 Prove that if every NP-hard language is also PSPACE-hard, then PSPACE = NP.

8.12 证明仅限于量词后面部分为合取范式的公式的TQBF问题仍然是 PSPACE 完备的。

8.12 Prove that the TQBF problem restricted to formulas in which the part following the quantifiers is in conjunctive normal form is still PSPACE-complete.

8.13 让我们定义A LBA = { M , w M是一个接受输入词w 的线性有界自动机。证明问题A LBA是 PSPACE 完备的。

8.13 Let A LBA = { M , w : M is a bounded linear automaton accepting input word w }. Show that the problem A LBA is PSPACE-complete.

*8.14 猫捉老鼠的游戏是由“猫”和“老鼠”两个玩家以任意无向图为棋盘进行的。在给定时间,每个玩家占据图的一个顶点。在交替移动中,玩家移动到与他们当前占据的顶点相邻的顶点。该图的一个顶点突出显示为“鼠标孔”。如果两个玩家都落在同一个顶点,则猫获胜。如果老鼠先于前一个洞到达洞,则它获胜。如果再次发生某种情况(即,当两个玩家同时占据他们之前占据的位置并且下一步属于同一玩家时),则游戏被视为平局。

*8.14 The game of cat and mouse is played by two players, "Cat" and "Mouse," using any undirected graph as the board. At any given time, each player occupies one vertex of the graph. In alternating moves, players move to the vertex adjacent to the one they currently occupy. One vertex of the graph is distinguished as the "Mouse Hole." The Cat wins if both players ever end up at the same vertex. The Mouse wins if it manages to reach the Hole before the previous vertex occurs. The game is considered a draw if either situation repeats itself (that is, if both players simultaneously occupy the positions they occupied previously, and the next move goes to the same player).

HAPPY-CAT = { G , c , m , h : G , c , m , h分别是猫、老鼠和洞的图、位置,只要满足以下条件,猫就有获胜策略它迈出了第一步}。

HAPPY-CAT = { G , c , m , h : G , c , m , h are the graph, positions of Cat, Mouse and Hole, respectively, such that Cat has a winning strategy as long as he makes the first move}.

证明HAPPY-CAT问题属于P类。(提示:解法并不复杂,也不依赖于博弈的详细定义。考虑整个博弈树。它的大小是指数级的,但可以用多项式搜索时间。)

Show that the HAPPY-CAT problem belongs to the class P. (Hint: The solution is not complicated and does not depend on the detailed definition of the game. Consider the entire game tree. It has exponential size but can be searched in polynomial time.)

8.15考虑下面问题 7.28 中描述的PUZZLE语言 的两人版本。每个玩家开始时都有一叠有序的扑克牌。玩家轮流将卡片放入盒子中,并可以选择将卡片放置在哪一侧。如果最后一叠洞中的所有洞都被堵塞,则玩家 I 获胜;如果任何洞未被堵塞,则玩家 II 获胜。证明对于给定的初始手牌,决定哪个玩家具有获胜策略的问题是 PSPACE 完成的。

8.15 Consider the following two-player version of the PUZZLE language described in Problem 7.28. Each player starts with an ordered pile of playing cards. Players take turns placing cards in a box and may choose which side to put a card on. Player I wins if all the holes in the final pile are blocked, or player II wins if any hole remains unblocked. Show that the problem of deciding which player has a winning strategy for a given initial arrangement of cards is PSPACE-complete.

8.16回想一下问题 7.46 中给出的MIN-FORMULA语言 的定义。

8.16 Recall the definition of the MIN-FORMULA language presented in task 7.46.

a. 证明MIN-FORMULA PSPACE。

a. Prove that MIN-FORMULA PSPACE.

b. 解释为什么以下推理不允许我们证明MIN-FORMULA coNP: 如果Φ MIN-FORMULA,则公式Φ对应于更小的等价公式。非确定性图灵机可以通过猜测该公式来检查Φ MIN-FORMULA 。

b. Explain why the following reasoning fails to show that MIN-FORMULA coNP: If Φ MIN-FORMULA , then there is a smaller equivalent formula to Φ . A nondeterministic Turing machine can check that Φ MIN-FORMULA by guessing this formula.

8.17A为正确放置括号的语言。例如,单词 (()) 和 (()(()))() 属于A,但单词 )( 不属于 A 。证明语言A属于 L 类。

8.17 Let A be a language of correctly placed parentheses. For example, the words (()) and (()(()))() belong to A , but the word )( does not. Prove that the language A belongs to the class L.

*8.18B为正确放置的圆括号和方括号的语言。例如,单词 ([()()]()[]) 属于B,但单词 ([)] 不属于 B 。证明语言B属于L类。

*8.18 Let B be a language of correctly placed parentheses and square brackets. For example, the word ([()()]()[]) belongs to B , but the word ([)] does not. Show that the language B belongs to the class L.

*8.19 Nim 游戏是使用几束棍子进行的。在一次移动中,玩家可以从一堆中移除非零数量的木棍。玩家轮流做出动作。拿走最后一根棍子的玩家就输了。假设在 Nim 游戏中,我们有一个包含s 1 , ..., s k根棍子的 k束系统。如果当每个数字以二进制形式写在另一个数字的下面(矩阵行与最低有效位对齐)时,如果每列位包含偶数个 1,则我们说系统是平衡的。证明以下两个事实:

*8.19 The game Nim is played with several bunches of sticks. In one move, a player can remove a nonzero number of sticks from a single bunch. Players take turns taking turns. The player who removes the last stick loses. Suppose that in the game of Nim we have a system of k bunches containing s 1 , …, s k sticks each. We say that the system is balanced if, when each of the numbers is written in binary one below the other (as rows of a matrix aligned to the least significant bits), each column of bits contains an even number of 1s. Prove the following two facts:

a. 当从不平衡系统开始时,只需一个步骤即可将其更改为平衡系统。

a. When starting from an unbalanced frame, there is a single move that changes it to a balanced one.

b. 当从平衡框架开始时,每一次移动都会将框架更改为不平衡框架。

b. When starting from a balanced frame, every single move changes the frame to an unbalanced one.

NIM = { s 1 , …, s k:每个s i都是一个二进制数,如果玩家 I 在该系统中开始,那么他在 Nim 中就有获胜策略}。使用先前有关平衡系统的事实来证明NIM L。

Let NIM = { s 1 , …, s k : each s i is a binary number and player I has a winning strategy in NIM if he starts in this system}. Use previous facts about balanced systems to show that NIM L.

8.20MULT = { a # b # c : a , b , c是二进制形式的自然数,并且a × b = c }。证明MULT L。

8.20 Let MULT = { a # b # c : a , b , c are natural numbers written in binary and a × b = c }. Prove that MULT L.

8.21 对于任何正整数x,x R是一个整数,其二进制形式是x的二进制形式的向后表示。 (我们假设x的二进制形式在其初始位置不包含零。)我们将定义函数R + : N N,其中R + ( x ) = x + x R

8.21 For any positive integer x, let x R be an integer whose binary form is the backward representation of the binary form of x . (We assume that the binary form of x has no leading zeros.) We define a function R + : N N , where R + ( x ) = x + x R .

A 2 = { x , y : R + ( x ) = y } 证明A 2 L。

a. Let A 2 = { x , y : R + ( x ) = y }. Prove that A 2 L.

b.A 3 = { < x , y > : R + ( R + ( x ))= y }。证明A 3 L。

b. Let A 3 = { x , y : R + ( R + ( x )) = y }. Prove that A 3 L.

8.22 a.ADD = { x , y , z x , y , z > 0 是二进制整数x + y = z}。证明ADD Î L。

8.22 a. Let ADD = { x , y , z : x , y , z > 0 are binary integers and x + y = z}. Prove that ADD Î L.

b.PAL-ADD = { x , y : x , y > 0 是二进制整数,其中二进制形式x + y是回文}。 (我们假设和的二进制形式没有前导零。回文是一个以相反顺序书写时等于其自身的单词。)证明PAL-ADD L。

b. Let PAL-ADD = { x , y : x , y > 0 be binary integers, where the binary form x + y is a palindrome}. (We assume that the binary form of the sum has no leading zeros. A palindrome is a word that is equal to itself when written in reverse order.) Prove that PAL-ADD L.

*8.23 让我们定义语言UCYCLE = { G : G是一个包含简单循环的无向图}。证明UCYCLE L。(注:G可能是无连通图。)

*8.23 Define the language UCYCLE = { G : G is an undirected graph containing a simple cycle}. Show that UCYCLE L. (Remark: G may be an unconnected graph.)

*8.24 对于每个n,显示两个长度为poly ( n )(关于n的多项式)的正则表达式R和S ,其中L( R ) L(S),但这些语言不同的第一个单词是指数长度。换句话说,对于某个常数 ε > 0 ,L( R ) 和 L(S) 预计会有所不同,但对于长度不超过 2 εn的所有单词都匹配。

*8.24 For each n, show two regular expressions R and S of length poly ( n ) (polynomial in n ), where L( R ) L(S), but the first word for which they differ has exponential length. In other words, L( R ) and L(S) are supposed to differ but be consistent for all words of length not exceeding 2 εn for some constant ε > 0.

8.25如果一个无向图的顶点可以分为两个集合,并且所有边都从第一个集合中的顶点通向第二个集合中的顶点,则该 无向图是二分图。证明图是二分图当且仅当它不包含具有奇数个顶点的环。设BIPARTITE = { G G是二分图}。证明BIPARTITE NL。

8.25 An undirected graph is bipartite if its vertices can be partitioned into two sets in such a way that all edges lead from a vertex in the first set to a vertex in the second set. Prove that a graph is bipartite if and only if it does not contain a cycle with an odd number of vertices. Let BIPARTITE = { G : G is a bipartite graph}. Prove that BIPARTITE NL.

8.26 让我们将UPATH定义为无向图的PATH问题的等价物。证明BIPARTITE ≤LUPATH 。(注:我们确实可以证明UPATH L,因此BIPARTITE L,但算法 [62] 太难在本书中呈现。)

8.26 Let us define UPATH as the analogue of the PATH problem for an undirected graph. Show that BIPARTITE ≤L UPATH . (Remark: We can in fact prove that UPATH L, and therefore BIPARTITE L, but the algorithm in [62] is too hard to present in this book.)

8.27回想一下,如果每两个顶点之间存在双向路径,则 有向图是强连通的。让

8.27 Recall that a directed graph is strongly connected if there are directed paths in both directions between any two vertices. Let

STRONGLY-CONNECTED = { G : G是强连通图}。

STRONGLY-CONNECTED = { G : G is a strongly connected graph}.

证明强连通问题是 NL 完备问题。

Prove that the STRONGLY-CONNECTED problem is NL-complete.

8.28BOTH NFA = { M 1 , M 2 M 1M 2是非确定性有限自动机,使得 L( M 1 ) L( M 2 ) Ø }。证明这两个NFA问题都是 NL 完备问题。

8.28 Let BOTH NFA = { M 1 , M 2 : M 1 and M 2 are nondeterministic finite automata such that L( M 1 ) L( M 2 ) Ø }. Show that the BOTH NFA problem is NL-complete.

8.29 证明问题A NFA是 NL 完备的。

8.29 Prove that the NFA problem A is NL-complete.

8.30 证明E DFA问题是NL完备问题。

8.30 Prove that the E DFA problem is NL-complete.

*8.31 证明2SAT问题是NL完备问题。

*8.31 Prove that the 2SAT problem is NL-complete.

8.32CNF H1 = { 〈Φ>Φ是一个可满足的 CNF 公式,其中每个子句包含任意数量的正(非否定)文字和至多一个否定文字。此外,每个否定文字在Φ } 公式中最多出现一次。证明CNF H1问题是 NL 完备问题。

8.32 Let CNF H1 = { 〈Φ〉 : Φ be a satisfiable CNF formula in which each clause contains an arbitrary number of positive (non-negated) literals and at most one negated literal. In addition, each negated literal appears at most once in the formula Φ }. Prove that CNF H1 is NL-complete.

*8.33 给出一个 NL 完备的上下文无关语言的例子。

*8.33 Give an example of a context-free language that is NL-complete.

A* 8.34 让我们定义语言CYCLE = {G G是一个包含有向循环的有向图}。证明CYCLE问题是 NL 完备问题。

A* 8.34 Define the language CYCLE = {G : G is a directed graph containing a directed cycle}. Show that the problem CYCLE is NL-complete.

精选解决方案

Selected solutions

8.5我们将构造一个解析ADFA语言的图灵M。当机器M接收到输入单词A , w (即编码后的 DFA)和单词w时,它会针对单词w模拟机器A ,跟踪机器A的当前状态和当前头部位置,并相应地更新它们。执行此模拟所需的内存为O (log n ),因为M可以通过存储指向输入字的指针来记住这些值中的每一个。

8.5 We construct a Turing machine M that resolves a DFA language A . Given an input word A , w , the encoded DFA, and a word w , M simulates A for word w , keeping track of the current state of A and the current head position, and updating them appropriately. The memory required to perform this simulation is O (log n ), since M can store each of these values ​​by storing a pointer to the input word.

8.7A 1A 2是由在对数内存中运行的非确定性机器N 1N 2解析的语言。我们将构建三个图灵机:N 解析语言A 1 A 2N °解析语言A 1 A 2N *解析语言A 1 *。这些机器的工作原理如下图所示。

8.7 Let A 1 and A 2 be languages ​​that are decided by nondeterministic machines N 1 and N 2 operating on logarithmic memory. We construct three Turing machines: N deciding the language A 1 A 2 , N ° deciding the language A 1 A 2 , and N * deciding the language A 1 * . These machines operate as follows.

机器N 不确定地选择是模拟机器N 1还是N 2。在每种情况下,当模拟机接受输入词时,N ⊔接受输入词。

Machine N nondeterministically chooses whether to simulate machine N 1 or N 2 . In each case, N accepts an input word whenever the simulated machine accepts it.

N °机器 不确定地选择输入单词中的一个位置,将其分成两个子单词。只有指向该位置的指针存储在工作磁带上 - 我们没有足够的内存来仅存储子字。N °然后针对第一个子字模拟机器N 1 ,做出非确定性选择来模拟机器N 1的非确定性。在到达N 1机器的接受状态的任何计算路径上,N °机器模拟第二子字的N 2 。在任何达到N2接受状态的计算路径中,机器接受N ° 。

Machine N ° nondeterministically chooses a position in the input word at which to split it into two subwords. Only a pointer to that position is kept on the work tape—we do not have enough memory to store the subwords themselves. N ° then simulates machine N 1 for the first subword, making nondeterministic choices to simulate the nondeterminism of machine N 1 . On any computation path that reaches an accepting state of machine N 1 , machine N ° simulates N 2 for the second subword. On any computation path that reaches an accepting state of machine N 2 , machine N ° accepts.

N *机的算法更为复杂,因此我们将描述其步骤。

The N * machine has a more complex algorithm, so we will describe its steps.

N * =“对于输入

N * = "For input word in :

1. 将两个输入指针p 1p 2初始化为值 0,即输入字的第一个符号之前的位置。

1. Initialize the two input pointers p 1 and p 2 to the value 0, i.e. the position immediately preceding the first symbol of the input word.

2.如果指针p 2之后没有出现符号,则 接受

2. Accept if no symbol appears after the indicator p 2 .

3.将p 2指针向右 移动到不确定选择的位置。

3. Move the pointer p 2 right to a nondeterministically chosen position.

4、模拟N 1机对字w的子字从指针p 1之后的位置到指针p 2的位置的 操作,利用其自身的非确定性来模拟N 1机的非确定性。

4. Simulate the operation of machine N 1 for the subword of word w from the position following pointer p 1 to the position of pointer p 2 , using its own nondeterminism to simulate the nondeterminism of machine N 1 .

5.如果该模拟路径到达N 1台机器 的接受状态,则将指针p 2复制到p 1并转至步骤2。如果该计算路径中N 1拒绝,则拒绝'。

5. If this simulation path reaches an accepting state of machine N 1 , copy the pointer p 2 to p 1 and go to step 2. If N 1 rejects on this computation path, reject ”.

8.34我们将把PATH 问题简化为CYCLE问题。这种缩减的想法是通过在图G中添加一条从顶点ts 的边来修改PATH问题的G , s , t 实例。如果G中存在从st的路径,则修改后的图G中将存在有向循环。然而,修改后的图G中可能存在其他循环,因为它们可能已经存在于图G本身中。为了解决这个问题,我们首先修改图G使其不包含环。可平级有向图是这样的图,其中顶点可以分为称为级别的组A 1A 2、...、A k,使得仅存在从某个级别到下一个更高级别的边。请注意,可水平图是非循环的。可平化图的PATH问题仍然是 NL 完备的,如以下无界PATH问题的简化所示。给定一个具有两个不同顶点st的图G,总共包含m 个顶点,我们将构建一个可水平图G' ,其水平是图G所有顶点的副本- 总共m 个副本。如果图G包含从顶点ij 的边,则我们创建从每个级别的顶点i到下一级的顶点j 的边。此外,我们在每个级别创建从顶点到顶点下一个级别的边。令s'为s在第一层的顶点, t'为t在最后一层的顶点。图G包含从顶点st的路径当且仅当 G' 包含从顶点s't' 的路径。如果我们通过添加从顶点t's'的边来修改G',我们就会减少PATH问题循环。这种缩减在计算上很简单,并且其实现是在对数存储器中运行的过程。此外,可以创建一个简单的过程来证明CYCLE NL。由此可见CYCLE问题是 NL 完备问题。

8.34 We reduce the PATH problem to the CYCLE problem . The idea of ​​this reduction is to modify the instance G , s , t 〉 of the PATH problem by adding an edge from vertex t to s in the graph G. If there is a path from s to t in G , then there will be a directed cycle in the modified graph G. However , there may be other cycles in the modified graph G , since they may already be present in G itself . To deal with this problem, we first modify G to be cycle-free. A levelable directed graph is one in which the vertices can be divided into groups A 1 , A 2 , …, A k called levels , so that there are only edges from some level to the next higher level. Note that a levelable graph is acyclic. The PATH problem for a levelable graph is still NL-complete, as shown by the following reduction of the unconstrained PATH problem . Given a graph G with two distinguished vertices s and t , containing a total of m vertices, we construct a levelable graph G' , whose levels are copies of all the vertices of G - a total of m copies. We construct an edge from vertex i at each level to vertex j at the next level, provided that G contains an edge from vertex i to j . Additionally, we construct an edge from vertex i at each level to vertex i at the next level. Let s' be a vertex s at the first level, and t' be a vertex t at the last level. The graph G contains a path from vertex s to t if and only if G' contains a path from vertex s' to t' . If we modify G' by adding an edge from vertex t' to s' , we obtain a reduction of the PATH problemto CYCLE . This reduction is computationally simple and its implementation is a procedure operating in logarithmic memory. Moreover, one can derive a simple procedure to show that CYCLE NL. It follows that the CYCLE problem is NL-complete.

9

难题

9

Difficult problems

有些计算问题原则上是可以解决的,但它们的解决方案需要大量的时间或内存,以至于无法在实践中应用。我们称此类问题为计算困难困难

There are computational problems that are solvable in principle, but whose solutions require so much time or memory that they cannot be applied in practice. Such problems are called computationally intractable or hard .

在第 7 章和第 8 章中,我们提出了几个被认为是困难的问题,尽管没有一个问题被证明是困难的。例如,大多数人认为SAT问题和所有其他 NP 完备问题都很困难,尽管他们不知道如何证明这一点。在本章中,我们将提供此类问题的示例,我们可以证明其难度。

In Chapters 7 and 8 we presented several problems that are believed to be hard, although no proof has been found for any of them that they are. For example, most people believe that the SAT problem and all other NP-complete problems are hard, although it is not known how to prove this. In this chapter we present examples of such problems for which we can prove their hardness.

为了展示这些例子,我们需要将图灵机的能力与它们可支配的时间或内存量联系起来的定理。我们将总结这一章,考虑证明属于 NP 类的问题是不可计算的可能性,这将使我们能够解决 PNP 的困境。首先,我们将提出一种相对化技术,使我们能够论证某些证明方法不会有效。然后我们讨论电路复杂性理论,一些研究人员选择的一种似乎很有前途的方法。

To present these examples, we need theorems relating the power of Turing machines to the amount of time or memory they have at their disposal. We conclude the chapter by considering the possibility of proving that problems in the class NP are uncomputable, which would resolve the P versus NP dilemma. We first present a technique of relativization that allows us to argue that certain methods of proof will not work. We then discuss circuit complexity theory, an approach that some researchers have chosen and that seems promising.

9.1

层次定理

9.1

Hierarchy Theorems

常识表明,如果我们给图灵机更多的时间或更多的内存,它应该扩大它可以解决的问题类别。例如,图灵机应该能够在n 3时间比在n 2时间解析更多的语言。层次定理表明,这种直觉是正确的,但在某些条件下,我们接下来将对此进行描述我们使用术语层次结构定理,因为这些定理表明时间和内存复杂度类并不相互相等 - 它们形成层次结构,其中具有较大资源边界(时间或内存)的类比具有较小资源边界的类包含更多语言。

Common sense suggests that if we give a Turing machine more time or more memory, it should enlarge the class of problems it can solve. For example, Turing machines should be able to decide more languages ​​in time n 3 than in time n 2 . The hierarchy theorems show that this intuition is correct, but under certain conditions, which we will describe later. We use the notion of the hierarchy theorem because these theorems show that the time-complexity and memory-complexity classes are not equal—they form hierarchies in which classes with larger resource bounds (time or memory) contain more languages ​​than classes with smaller bounds.

内存复杂度的层次定理比时间复杂度的定理稍微简单一些,所以我们先展示它。出于技术原因,我们将首先介绍以下定义。

The hierarchy theorem for memory complexity is somewhat simpler than the one for time complexity, so we will show it first. For technical reasons, we will start by introducing the following definition.

定义 9.1

Definition 9.1

函数f : N N,其中f ( n ) 至少具有O (log n ) 阶,如果将字 1 n转换为数字f ( n )的二进制表示的函数在内存中是可计算的,则称为内存可构造函数O ( f ( n ))。1

A function f : N N , where f ( n ) is of order at least O (log n ), is called memory constructible if the function transforming the word 1 n into the binary representation of the number f ( n ) is computable in memory O ( f ( n )). 1

换句话说,如果有某个图灵机在内存O ( f ( n )) 中运行,并且在针对输入字1n运行时始终以写在磁带上的二进制形式f ( n ) 停止,则函数f是内存可构造的。为了时间和内存的可构造性,返回非整数值的函数(例如n log 2 nn)将向下舍入到最接近的整数。

In other words, a function f is memory constructible if there exists some Turing machine running in memory O ( f ( n )) that always halts with the binary form of f ( n ) written out on the tape when run for input word 1n . For the purposes of time and space constructibility, functions that return non-integer values, such as n log 2 n or n , are rounded down to the nearest integer.

9.2

Example 9.2

所有至少具有O (log n ) 阶的常用函数都是可在内存中构造的,包括函数 log 2 nn log 2 nn 2

All common functions that are at least of order O (log n ) are constructible in memory, including the functions log 2 n , n log 2 n , and n 2 .

例如,函数n 2是内存可构造的,因为机器可以通过计算 1 的数量从输入字 1 n获得二进制形式n,然后使用n与自身相乘的任何标准方法来计算n 2。使用的总内存为O ( n ),这无疑在O ( n2 )渐近极限之内。

For example, the function n 2 is constructible in memory, since the machine can take the input word 1 n and convert it to binary form n by counting the number of ones, and then compute n 2 by any standard method of multiplying n by itself. The total memory used is O ( n ), which is certainly within the asymptotic bound O ( n 2 ).

为了证明以o ( n ) 为界的函数f ( n ) 是可内存构造的,我们使用单独的只读输入带,如第 8.4 节中定义次线性内存复杂性一样。例如,这样的机器可以计算一个将 1 n映射到 log 2 n的二进制表示的函数,如下所示。首先,当磁头在输入磁带上移动时,它会使用磁带找到二进制形式的输入字中 1 的数量。然后,给定构建带上数字n的二进制形式,它可以通过计算该数字的位数来计算 log 2 n 。

To show that the function f ( n ) bounded by o ( n ) is memory constructible, we use a separate read-only input tape, as in the definition of sublinear memory complexity in Section 8.4. Such a machine can, for example, compute a function that maps 1 n to the binary representation of log 2 n as follows. First, it finds the number of ones in the input word in binary form, using the work tape as the head moves along the input tape. Then, given the binary representation of n on the work tape, it can compute log 2 n by counting the number of bits in that number.

内存可构造性在内存层次定理中的作用可以通过考虑以下情况来理解。如果f ( n )和g ( n )是内存约束,其中f ( n )渐近大于g ( n ),我们可以期望机器能够解析内存f ( n )中比内存中更多的语言内存g ( n )。然而,假设f ( n ) 只比g ( n ) 稍大一些,而且是一个非常小且难以计算的量。在这种情况下,机器可能无法有效地使用额外的内存,因为简单地分配它可能需要比可用内存更多的内存。在这种情况下,机器将无法在内存f ( n ) 中计算比在内存g ( n ) 中更多的语言。假设f ( n ) 是内存可构造的,可以避免这种情况,并且可以证明机器能够比任何渐进更小的内存约束下计算更多,如以下定理所述。

The role of memory constructibility in the memory hierarchy theorem can be understood by considering the following situation. If f ( n ) and g ( n ) are memory constraints, where f ( n ) is asymptotically larger than g ( n ), we can expect the machine to be able to resolve more languages ​​in f ( n ) than in g ( n ) . However, suppose that f ( n ) is larger than g ( n ) only slightly, by a very small and incomputable amount. In such a case, the machine may not be able to make efficient use of the extra memory, since its computation alone may require more memory than is available. In such a case, the machine will not be able to compute more languages ​​in f ( n ) than in g ( n ) . The assumption that f ( n ) is memory constructible avoids this situation and allows us to prove that the machine can compute more than with any asymptotically smaller memory constraints, as the following theorem states.

定理9.3

Theorem 9.3

内存层次定理对于任何可内存构造的函数f : N N,存在一种在内存O ( f ( n )) 中可判定的语言A,但在内存O ( f ( n )) 中不可判定。

Memory Hierarchy Theorem For any memory-constructible function f : N N there exists a language A that is decidable in memory O ( f ( n )) but not in memory O ( f ( n )).

证明的概念 我们需要展示一种具有两个属性的语言A。首先,语言A在内存O ( f ( n )) 中是可判定的。其次, A在内存中不能( f ( n ))决定

Concept of Proof We need to show a language A that has two properties. First, the language A is decidable in space O ( f ( n )). Second, A cannot be decidable in space O ( f ( n )).

我们将通过给出解决它的算法D来呈现语言A。算法D在O ( f ( n ))内存中运行,从而保证了第一个性质的实现。此外,算法D将通过( f ( n ))确保语言A与任何内存可判定的语言不同,这保证了第二个属性的实现。语言A与前面讨论的语言不同之处在于它除了算法之外没有其他定义。因此,我们无法呈现语言A的简单心理形象。

We will introduce a language A by giving an algorithm D that decides it . Algorithm D runs in memory O ( f ( n )), thus guaranteeing the first property. Moreover, algorithm D will ensure that language A is different from any language that is decidable in memory O ( f ( n )), thus guaranteeing the second property. Language A differs from the languages ​​discussed earlier in that it has no definition other than the algorithmic one. For this reason, we cannot present a simple mental picture of language A .

为了确保语言A不能在内存中通过( f ( n ))求解,我们将基于我们之前在第 202 页的定理 4.11 中证明问题A TM不可解时使用的对角化方法来设计算法D。如果M是一个图灵机决定内存中的语言o ( f ( n )),算法D将确保语言A与该机器的语言至少在一个地方不同。什么?与M机本身的描述相符的。

To ensure that language A is undecidable in memory by ( f ( n )), we design an algorithm D based on the diagonalization method we used earlier to prove the undecidability of the A TM problem in Theorem 4.11 on page 202. If M is a Turing machine that resolves language A in memory by ( f ( n )), algorithm D will ensure that language A differs from that machine in at least one place. Which one? The one that corresponds to the description of M itself .

我们来看看算法D是如何工作的。一般来说,D将其输入词视为图灵机M的描述。 (如果输入词不是任何图灵机的描述,那么D对该词的操作不会产生任何后果,因此在这种情况下我们可以决定D拒绝。)然后D为相同的输入词触发机器M - 也就是说,M - 施加内存约束f ( n )。如果M在没有超过此限制的情况下停止,则当且仅当机器M拒绝输入字时D才接受。如果机器M不停止,D就会拒绝。因此,如果机器M运行在内存f ( n ) 中,那么机器D有足够的空间来保证它的语言与机器M的语言不同。如果不是这种情况,则机器D没有足够的内存来弄清楚机器M正在做什么。幸运的是,我们并不要求机器D的行为与不在( f ( n ))的内存中运行的机器不同,因此在这种情况下,机器D的操作并不重要。

Let's look at how algorithm D works . In general, D treats its input word as a description of a Turing machine M . (If the input word is not a description of any Turing machine, then D's action on that word has no consequences, so in that case we can decide that D rejects.) Then D runs machine M on the same input word—that is, M —by imposing a memory constraint f ( n ). If M halts within this constraint, then D accepts if and only if M rejects the input word. If M does not halt, D simply rejects. Thus, if machine M operates on memory f ( n ), then machine D has enough space to guarantee that its language is different from the language of machine M . If it is not, then machine D does not have enough memory to figure out what machine M is doing . Fortunately, we do not require machine D to behave differently from machines that do not operate on memory o ( f ( n )), so in such situations, the action of machine D does not matter.

这个描述包含了证据的本质,但省略了许多重要的细节。如果机器M运行在内存 o( f ( n )) 中,那么机器D必须保证它的语言与机器M的语言不同。然而,即使机器M在o ( f ( n )) 内存中运行,它也可能会为较小的n使用超过f ( n ) 的内存,而渐近约束对此不适用。因此可能会发生机器D没有足够的内存来终止机器M 的输入单词<M>,从而错过了避开机器M的语言的机会。因此,如果我们不小心,机器D可能会解析与机器M相同的语言,这意味着我们不会收到定理的证明。

This description contains the gist of the proof, but omits many important details. If machine M runs on memory o( f ( n )), then machine D must guarantee that its language is different from the language of machine M . However, even if machine M runs on memory o ( f ( n )), it may use more than f ( n ) memory for small n , for which the asymptotic constraints do not apply. It may therefore happen that machine D does not have enough memory to terminate M for input word M , and thus misses the opportunity to avoid the language of machine M . Thus, if we are not careful, machine D may turn out to resolve the same language as machine M , and so we will not get a proof of our theorem.

我们可以通过修改机器D使其具有额外的功能来避免与机器语言的“冲突”来解决这个问题。D不是仅在接收到输入字M 时才启动机器M ,而是在接收到M 10 *形式的输入字时启动机器M,该字由代码M组成,并填充数字 1和一些零。然后,如果M确实在内存o ( f ( n )) 中运行,则机器D将有足够的内存来完成输入单词M 10 k的操作(对于某个较大的k值),因为这样渐近行为就已经采取了影响。

We can solve this problem by modifying machine D so that it has additional ways of avoiding "collisions" with the machine language. Instead of running machine M only when D receives an input word M , it will run machine M when it receives an input word of the form M 10 * , that is, a word consisting of the code for M plus a 1 and some number of zeros. Then, if M really runs in memory o ( f ( n )), machine D will have enough memory to complete the operation for an input word M 10 k for some large value of k , since then the asymptotic behavior will kick in.

还有一个技术问题。当机器D对某个单词运行M时,机器M尽管只使用了有限的内存,但可能会进入无限循环。然而,D旨在成为决胜局机器,因此我们必须保证D在模拟机器M时不会循环。任何运行在o ( f ( n )) 内存中的机器最多消耗 2o ( f ( n ) )时间。我们将修改机器D以计算模拟机器M中使用的步数。如果该计数器超过 2 f ( n ),则机器D停止并丢弃。

There is another technical problem. When machine D runs M for some word, machine M may enter an infinite loop despite using only a finite amount of memory. However, D is to be the tie-breaker, so we must guarantee that D does not loop during the simulation of machine M . Any machine running in memory o ( f ( n )) uses at most 2 o ( f ( n )) time. We modify machine D so that it counts the steps used in simulating machine M . If this counter exceeds 2 f ( n ) , machine D aborts and rejects.

证明 以下在内存O ( f ( n )) 中运行的算法D可以解析语言 A,而语言 A 在内存O ( f ( n ))中是不可判定的

Proof The following algorithm D running in memory O ( f ( n )) decides the language A, which is not decidable in memory O ( f ( n )).

D =“对于中的输入词:

D = "For input word in :

  1. n为单词的长度。
  2. Let n be the length of the word in .
  3. 使用心理可构建性计算f ( n ),并在胶带上标记此大小的区域。如果机器尝试在后续步骤中使用更多内存,请丢弃
  4. Compute f ( n ), using memory constructibility, and mark a region of this size on the tape. If in later steps the machine tries to use more memory, discard .
  5. 如果对于某些图灵机M来说w不是〈M〉10 *形式,拒绝
  6. If there is no M 10 * of the form for some Turing machine M , reject .
  7. 模拟机器M的单词w,同时计算该模拟中使用的步骤。如果步数超过2f ( n )拒绝
  8. Simulate the machine M for word w , while counting the steps used in this simulation. If the number of steps exceeds the value 2 f ( n ) , reject .
  9. 如果机器M接受,则拒绝。如果机器M拒绝,则接受
  10. If machine M accepts, reject . If machine M rejects, accept ”.

在步骤 4 中,我们需要提供额外的模拟详细信息,以便能够确定所使用的内存量。模拟的图灵机M有一个任意的磁带字母表,而机器D有一个固定的磁带字母表,所以我们必须用机器D的磁带上的几个单元来模拟机器M的磁带上的每个单元。因此,模拟给所使用的内存量带来了恒定因子的开销。换句话说,如果机器M在内存g ( n )中运行,则机器D需要dg ( n ) 内存进行模拟,其中d是某个取决于M 的常数。

In Step 4, we need to specify additional details of the simulation to determine the amount of memory used. The simulated Turing machine M has an arbitrary tape alphabet, while machine D has a fixed tape alphabet, so we must simulate each cell on the tape of machine M with several cells on the tape of machine D . Thus, the simulation introduces an overhead of a constant factor in the amount of memory used. In other words, if machine M runs on g ( n ) memory , then machine D needs dg ( n ) memory to simulate it, where d is some constant depending on M .

D是决定性的机器,因为每一步只能花费有限的时间。设A为机器D解析的语言。很明显,A在内存O ( f ( n )) 中是可判定的,因为这就是机器D 的工作方式。现在我们将证明语言A在内存中不能( f ( n )) 决定。

D is a decidable machine, since each step can take only a finite time. Let A be a language decidable by D . It is obvious that A is decidable in O ( f ( n )) space, since that is how D works . We now show that A is not decidable in O ( f ( n )) space.

为了得出矛盾,假设某个图灵机M在内存g ( n ) 中解析语言A,其中g ( n ) 是o ( f ( n ))。正如我们之前提到的,机器D可以针对某个常数d在内存dg ( n ) 中模拟M。由于g ( n ) 是 o( f ( n )),因此存在某个常数n 0使得dg ( n ) < f ( n ) 对于所有nn 0。因此,只要输入字的长度至少为n 0 , D对机器M的模拟就会一直运行直到停止。让我们看看当机器D针对输入单词M 10 n 0启动时会发生什么。该字的长度大于n 0,因此步骤4的模拟将完成。这意味着对于相同的输入单词,机器D会做出与机器M相反的决定。但这意味着M无法解析语言A,这与我们的假设相反。由此可见,语言A在内存o ( f ( n )) 中是不可判定的。

To arrive at a contradiction, suppose that some Turing machine M resolves language A in memory g ( n ), where g ( n ) is o ( f ( n )). As mentioned earlier, machine D can simulate M in memory dg ( n ) for some constant d . Since g ( n ) is o( f ( n )), there is some constant n 0 such that dg ( n ) < f ( n ) for all nn 0 . Thus, the simulation of machine M by D will run until it stops as long as the input word is at least n 0 . Let us see what happens when machine D is started for an input word M 10 n 0 . This word is longer than n 0 , so the simulation in step 4 is completed. This means that machine D will make the opposite decision compared to machine M for the same input word. But this means that M does not decide the language A , which is a contradiction to our assumption. It follows that A is not decidable in memory o ( f ( n )).

结论 9.4

Application 9.4

对于任意两个函数f 1 , f 2 : N N,其中f 1 ( n ) 是o ( f 2 ( n )) 并且f 2是内存可构造的,我们持有 SPACE( f 1 ( n )) SPACE( f 2n))。2

For any two functions f 1 , f 2 : N N , where f 1 ( n ) is o ( f 2 ( n )) and f 2 is constructible in memory, we have SPACE( f 1 ( n )) SPACE( f 2 ( n )). 2

这个结论使我们能够区分不同类别的内存复杂性。例如,我们可以证明函数n c对于任何自然数c都是内存可构造的。因此,对于两个自然数c 1 < c 2我们可以证明 SPACE( n c 1 ) SPACE( n c 2 )。只需付出一点努力,就可以证明函数nc对于任何有理数c > 0都是可构造的,并将此包含范围扩展到包括有理数 0 ≤ c 1 < c 2。注意到任何两个实数 ε 1 < ε 2之间总是有两个有理数c 1c 2,使得 ε 1 < c 1 < c 2 < ε 2,我们得到另一个结论,显示 PSPACE 类中的类层次结构。

This corollary allows us to separate different classes of memory complexity. For example, we can show that the function n c is memory constructible for any natural number c . Hence, for two natural numbers c 1 < c 2 , we can show that SPACE( n c 1 ) SPACE( n c 2 ). With a little effort, one can show that the function n c is memory constructible for any rational number c > 0, by extending this inclusion to include the rational numbers 0 ≤ c 1 < c 2 . Noting that between any two real numbers ε 1 < ε 2 , there are always two rational numbers c 1 and c 2 , such that ε 1 < c 1 < c 2 < ε 2 , we get another corollary showing the hierarchy of classes within the class PSPACE.

结论 9.5

Application 9.5

对于任意两个实数 0 ≤ ε 1 < ε 2成立

For any two real numbers 0 ≤ ε 1 < ε 2 it holds

空间( n ε 1 ) 空间( n ε 2 )。

SPACE( n ε 1 ) SPACE( n ε 2 ).

我们还可以使用内存层次定理来证明我们之前看到的两类内存复杂性是不同的。

We can also use the memory hierarchy theorem to show that the two classes of memory complexity we encountered earlier are different.

结论 9.6

Application 9.6

NL P 空间。

NL PSPACE.

证明 萨维奇定理指出 NL SPACE(log 2 n ),而内存层次结构定理指出 SPACE(log 2 n ) SPACE( n )。该提案的主题源于这两个结论。正如我们之前在第 354 页看到的,这样的分割表明TQBF NL,因为TQBF是一个关于减少对数内存的 PSPACE 完备问题。

Proof Savitch's theorem states that NL SPACE(log 2 n ), and the memory hierarchy theorem states that SPACE(log 2 n ) SPACE( n ). These two inclusions imply the corollary. As we noted earlier on page 354, such a separation shows that TQBF NL, since TQBF is a PSPACE-complete problem with respect to reduction in logarithmic memory.

现在我们可以转向本章的主要目标:证明理论上可判定但实际上不可判定的问题的存在——即可判定但计算上困难的问题。每个 SPACE( n k ) 类都包含在类 (n log n ) 中,而 (n log n ) 类又严格包含在 SPACE(2 n ) 类中。我们获得了另一个结论,显示了类 PSPACE 和 EXPSPACE = k SPACE(2 n k )之间的差异。

We can now move on to the main goal of this chapter: to show the existence of problems that are decidable in theory but not in practice—that is, problems that are decidable but computationally intractable. Each of the classes SPACE( n k ) is contained in the class (n log n ), which in turn is strictly contained in the class SPACE(2 n ). This gives us an additional corollary showing the difference between the classes PSPACE and EXPSPACE = k SPACE(2 n k ).

结论 9.7

Application 9.7

PSPACE EXPSPACE。

PSPACE EXPSPACE.

这个结论指出,存在不可计算的可判定问题,因为解决这些问题的过程必须使用大于多项式内存的内存。这种语言是相当人为的 - 仅出于区分计算复杂性类别的目的而有趣。我们将用它们来证明其他更自然的语言的不可计算性。但首先我们将处理时间层次定理。

This corollary states the existence of decidable problems that are uncomputable in the sense that the procedures that solve them must use more than polynomial memory. Such languages ​​are quite artificial—interesting only for the purposes of distinguishing classes of computational complexity. We will use them to prove the uncomputability of other, more natural languages. But first we will deal with the time hierarchy theorem.

定义 9.8

Definition 9.8

函数t : N N,其中t ( n ) 至少为O ( n log n ) 阶,如果将字 1 n转换为数字t ( n ) 的二进制形式的函数可计算为时间O ( t ( n ))。

A function t : N N , where t ( n ) is of order at least O ( n log n ), is called time-constructible if the function transforming the word 1 n into the binary form of the number t ( n ) is computable in time O ( t ( n )).

换句话说,如果有某个图灵机在时间O ( t ( n )) 中运行,则函数t是时间可构造的,当该图灵机针对输入字 1n 启动时,​​是以写入的数字t ( n ) 的二进制表示形式停止磁带。

In other words, a function t is time-constructible if there exists some O ( t ( n )) Turing machine that, when started for input word 1n, always halts with the binary representation of the number t ( n ) written out to the tape.

9.9

Example 9.9

所有至少具有n log n值的常见函数都是可时间构造的,包括函数n log nn n、 n 2和 2 n

All common functions that are at least n log n in value are constructible in time, including the functions n log n , n n , n 2 , and 2 n .

例如,为了证明n n是暂时可构造的,我们首先构建一个图灵机来计算二进制中 1 的数量。为此,机器沿着磁带移动计数器,每个位置加 1,直到到达数据末尾。这部分需要O ( n log n ) 步骤,因为对于输入字中的n 个位置中的每一个都需要O(log n ) 步骤。然后根据n 的二进制表示计算数字ë n n û的二进制形式。计算该值的任何合理方法都需要O ( n log n ) 时间运行,因为我们处理的数字长度为O (log n ) 量级。

For example, to show that n n is time-constructible, we first build a Turing machine that counts the number of 1s in binary. To do this, the machine rolls the counter along the tape, incrementing it by 1 for each position, until it reaches the end of the data. This part takes O ( n log n ) steps, since it takes O(log n ) steps to get to each of the n positions in the input word. Then the binary form of the number ë n n û is computed from the binary representation of n . Any reasonable method of computing this value runs in O ( n log n ) time , since the lengths of the numbers we are dealing with are of order O (log n ).

时间层次定理等价于定理 9.3,但时间复杂度不同。由于技术原因(我们将在证明中看到),该定理比我们为记忆证明的定理稍弱。虽然内存约束的任何渐近增加,只要它是内存可构造的,都会扩展已解析语言的类别,但就时间而言,我们必须通过对数因子进一步增加时间约束,以确保我们可以解析其他语言。据推测,“更密集”的时间层次定理是正确的,但我们目前还没有办法证明它。时间层次定理的这一方面的出现是因为我们使用单带图灵机来测量时间复杂度。对于其他计算模型,可以证明具有更严格的时间层次结构的定理。

The time hierarchy theorem is the equivalent of Theorem 9.3, but for time complexity. For technical reasons that we will see in the proof, this theorem is somewhat weaker than the one we proved for memory. While any asymptotic increase in the memory bounds, as long as they are memory-constructible, extends the class of negotiable languages, in the case of time we must further increase the time bounds by a logarithmic factor to be sure that we can resolve additional languages. Presumably the “denser” time hierarchy theorem is true, but we currently know of no way to prove it. This aspect of the time hierarchy theorem occurs because time complexity is measured in single-tape Turing machines. For other models of computation, theorems about a tighter time hierarchy can be proved.

定理9.10

Theorem 9.10

时间层次定理对于任何时间可构造函数t : N N,存在一种在时间O ( t ( n )) 可判定的语言A ,但在时间o ( t ( n )/log t ( n ))不可判定。

Time Hierarchy Theorem For any time-constructible function t : N N there exists a language A that is decidable in time O ( t ( n )) but undecidable in time o ( t ( n )/ log t ( n )).

证明的概念 证明类似于定理9.3 的证明。我们将构建一个图灵机D ,它在O ( t ( n ))时间内解析语言A。我们还将证明语言A无法在时间o ( t ( n )/ log t ( n ))内解析,机器D输入单词的形式为<M> 10 * 它通过不超过t ( n ) 步模拟机器M的输入单词w 。如果机器M在这个时限内完成了计算,那么D将返回与机器M给出的结果

Concept of the Proof The proof is similar to the proof of Theorem 9.3. We construct a Turing machine D that decides language A in time O ( t ( n )). We also show that language A cannot be decided in time o ( t ( n )/ log t ( n )). In this case, the input word to machine D is of the formM 10 * ; it simulates machine M for input word w in no more than t ( n ) steps. If machine M finishes within this time limit, then D will return the inverse of the result given by machine M .

证明中的一个重要区别涉及模拟机器M的成本,同时计算用于模拟的步骤数。机器D必须在有限的时间内进行高效模拟,使其本身在时间O ( t ( n )) 内运行,同时确保其语言在时间O ( t ( n )/log t ( n )) 内不可判定。在内存复杂性的情况下,模拟使复杂性增加了一个常数因子,正如我们在定理 9.3 的证明中看到的那样。在时间复杂度的情况下,模拟导致复杂度增加对数因子。这种增加的开销是定理中出现因子 1/log t ( n )的原因。如果我们知道如何在另一台单带机上模拟给定单带图灵机的给定步骤数,并且效率损失最多为一个常数因子,我们将能够通过改变表达式o来加强这个定理。 ( t ( n )/log t ( n )) 到仅( t ( n ))。然而,目前还没有这种类型的有效模拟。

An important difference in the proof concerns the cost of simulating M while counting the number of steps spent on the simulation. D must efficiently perform the simulation in a bounded time, so that it runs by itself in time O ( t ( n )), while ensuring that its language is not decidable in time o ( t ( n )/ log t ( n )). In the case of memory complexity, simulation introduces an increase in complexity by a constant factor, as we saw in the proof of Theorem 9.3. In the case of time complexity, simulation introduces an increase in complexity by a logarithmic factor. This increased overhead is the reason for the factor 1/ log t ( n ) in the theorem. If we knew how to simulate a given number of steps of a given single-tape Turing machine on another single-tape machine, with an efficiency loss of at most a constant factor, we could strengthen the theorem by changing the expression o ( t ( n )/ log t ( n )) to o ( t ( n )) itself . However, no efficient simulation of this kind is known.

证明 以下算法D在时间O ( t ( n )) 内运行,可解析语言A,而语言 A 在时间O ( t ( n )/log t ( n )) 内不可判定。

Proof The following O ( t ( n ))time algorithm D decides the language A , which is not decidable in time o ( t ( n )/log t ( n )).

D =“对于中的输入词:

D = "For input word in :

  1. n为w的长度。
  2. Let n be the length of w .
  3. 使用时间可构造性属性计算t ( n ),并将é t ( n )/ log t ( n ) 的值存储在二进制计数器中。在用于完成步骤 4 和 5 的每个操作之前,将此计数器减 1。如果计数器达到 0则丢弃
  4. Calculate t ( n ) using the time constructibility property and store the value of é t ( n )/ log t ( n ) in a binary counter. Decrement this counter by 1 before each operation used to implement steps 4 and 5. If the counter reaches  0 , discard .
  5. 如果对于某个图灵机M来说,单词w的形式不是M 10 *,则拒绝
  6. If a word in is not of the form M 10 * for some Turing machine M , reject .
  7. 运行M机器来查找单词w
  8. Start machine M for word w .
  9. 如果M接受,则拒绝。如果M拒绝,则接受
  10. If M accepts, reject . If M rejects, accept ”.

我们将分析该算法的每一步以确定其运行时间。步骤1、2和3可以在O( t ( n ))内执行。

We will analyze each step of this algorithm to determine its running time. Steps 1, 2, and 3 can be completed in time O( t ( n )).

在步骤 4 中,每次机器D模拟机器M的一个步骤时,它都会检索M 的当前状态以及该机器头下磁带上的符号,并在其转换函数中搜索M 的下一个操作,以便它可以相应地更新磁带3的状态和内容。所有这三个对象(状态、磁带符号和转换函数)都存储在机器D的磁带上的某个位置。如果它们存储的位置彼此相距较远,则机器D在模拟机器M的每个步骤时将需要许多步骤来收集此信息。因此,D始终将这些信息保留在身边。

In step 4, each time machine D simulates one step of machine M , it retrieves the current state of M along with the symbol on the tape under the head of that machine and looks up the next operation M in its transition function so that it can update the state and contents of tape 3 accordingly . All three of these objects (state, tape symbol, and transition function) are stored somewhere on the tape of machine D . If they were stored far apart from each other, machine D would require many steps to gather this information in the simulation of each individual step of machine M . Therefore, D always keeps this information close to itself.

我们可以将单个D机磁带视为被分为多个磁道。表示两条路径的一种方法是将一条路径的信息存储在奇数位置,另一条路径的信息存储在偶数位置。或者,可以通过扩大机器D的磁带字母表以包括每一对符号来实现双磁道效果:一个用于上磁道,一个用于下磁道。可以通过类似的方式获得其他路径。请注意,如果路径数量固定,则多个路径只会使运行时间增加一个常数因子。在我们的例子中,机器D有 3 条路径。

We can think of a single tape of a D machine as if it were divided into several tracks . One way to represent two tracks would be to store the information of one track in the odd positions and the other in the even positions. Alternatively, the effect of two tracks can be achieved by enlarging the tape alphabet of D to contain each pair of symbols: one for the top track and one for the bottom track. Additional tracks can be obtained in an analogous way. Note that multiple tracks introduce an increase in running time only by a constant factor, provided that the number of tracks is fixed. In our case, D has three tracks.

一条路径包含来自机器M磁带的信息,另一条路径保存机器M的当前状态和转换函数的副本。在模拟期间,机器D存储关于靠近机器M在第一磁道上的当前磁头位置的第二磁道的信息。每次机器M的磁头位置发生变化时,机器D都会将第二个轨道的全部内容移动到磁头附近。由于第二条路径上的信息量仅取决于机器M而不是其输入字的长度,因此这种移位只会将模拟时间增加一个常数因子。此外,因为必要的信息存储在一起,所以在其转换函数中搜索机器M的下一步移动并更新其磁带的成本是恒定的。因此,如果机器M在时间g ( n )内运行,机器D可以在时间O ( g ( n )) 内对其进行模拟。

One track contains the information from the tape of machine M , and the other stores the current state and a copy of the transition function of machine M . During the simulation, machine D stores the information on the second track near the current position of machine M ' s head on the first track. Whenever the head position of machine M changes , machine D shifts the entire contents of the second track to be near the head. Since the amount of information on the second track depends only on machine M , not on the length of its input word, this shifting increases the simulation time only by a constant factor. Moreover, because the necessary information is stored close together, the costs of finding M ' s next move in its transition function and updating its tape are constant. Thus, if machine M operates in time g ( n ), machine D can simulate it in time O ( g ( n )).

在步骤 4 中的每次操作之后,机器D必须递减步骤 2 中最初设置的计数器。在我们的仿真中,D可以通过将二进制形式的计数器存储在磁道 3 上并将其移位为在当前头部位置附近。该分子中存储的数字大小的数量级为t ( n )/ log t ( n ),因此其长度为 log( t ( n )/ log t ( n )),因此O (log t ( n ))。因此,每一步更新和移动计数器的成本都会使仿真时间增加 log t ( n )倍。因此总运行时间为O ( t ( n ))。由此可见,语言A在时间O ( t ( n ))时是可判定的。

After each operation in step 4, machine D must decrement the counter that was initially set in step 2. In our simulation, D can do this without significantly increasing the simulation time by storing the counter in binary form on track 3 and moving it so that it is near the current head position. The size of the number stored in this counter is of the order of magnitude t ( n )/ log t ( n ), so its length is log( t ( n )/ log t ( n )), and therefore O (log t ( n )). Hence, the cost of updating and moving the counter at each step increases the simulation time by a factor of log t ( n ). The total running time is therefore O ( t ( n )). It follows that language A is decidable in time O ( t ( n )).

为了证明语言A在时间o ( t ( n )/ log t ( n ))时不可判定,我们将使用类似于定理 9.3 证明中使用的推理。为了得出矛盾,我们假设有一个图灵机M在时间g ( n )内解析语言 A ,其中g ( n ) 的阶数为o ( t ( n )/log t ( n ))。机器D可以在dg ( n )时间内模拟机器M ,其中d是某个常数。如果总仿真时间(不包括更新计步器所需的时间)最多为t ( n )/ log t ( n ),则仿真将运行完成。由于g ( n ) 的阶数为o ( t ( n )/ log t ( n )),因此存在某个常数n 0使得dg ( n ) < t ( n )/ log t ( n ) 对于每个nn 0 .这意味着只要输入字长至少为n 0,机器D对机器M的模拟就会完成。考虑一下当我们针对输入单词M 10 n 0运行机器D时会发生什么。该字长于n 0,因此步骤4中的模拟将结束。由此可见,对于相同的输入字,机器D将产生与机器M相反的结果。因此,机器M不会解析语言A,这与我们的假设相反。因此,语言A在时间o ( t ( n )/log  t ( n ))时不可判定。

To show that A is not decidable in time o ( t ( n )/log t ( n )), we use reasoning analogous to that used in the proof of Theorem 9.3. To achieve a contradiction, assume that there exists a Turing machine M that decides A in time g ( n ), where g ( n ) is of order o ( t ( n )/log t ( n )). A machine D can simulate M in time dg ( n ), where d is some constant. If the total simulation time (excluding the time needed to update the step counter) is at most t ( n )/log t ( n ), the simulation will run to completion. Since g ( n ) is of order o ( t ( n )/ log t ( n )), there is some constant n 0 such that dg ( n ) < t ( n )/ log t ( n ) for all nn 0 . This means that the simulation of machine M by machine D will terminate as long as the input word is at least n 0 . Consider what happens when we run machine D for an input word M 10 n 0 . This word is longer than n 0 , so the simulation in step 4 will terminate. It follows that machine D will obtain the opposite result of machine M for the same input word. Therefore, machine M does not decide language A , which is a contradiction of our assumption. Hence language A is not decidable in time o ( t ( n )/ log  t ( n )).

我们可以针对时间复杂度得出结论,类似于结论 9.4、9.5 和 9.7。

We can formulate corollaries for time complexity analogous to corollaries 9.4, 9.5, and 9.7.

请求 9/11

Motion 9.11

对于任意两个函数t 1 , t 2 : N N,其中t 1 ( n ) 为o ( t 2 ( n )/ log t 2 ( n )) 并且函数t 2是时间可构造的, TIME( t 1 ( n )) 时间( t 2 ( n ))。

For any two functions t 1 , t 2 : N N , where t 1 ( n ) is o ( t 2 ( n )/ log t 2 ( n )) and the function t 2 is time constructible, we have TIME( t 1 ( n )) TIME( t 2 ( n )).

申请 9/12

Application 9.12

对于任意实数 1 ≤ ε 1 < ε 2存在 TIME( n ε 1 ) TIME( n ε 2 )。

For any real numbers 1 ≤ ε 1 < ε 2 we have TIME( n ε 1 ) TIME( n ε 2 ).

申请 9/13

Motion 9.13

P EXPTIME。

P EXPTIME.

指数记忆完整性

Exponential memory completeness

我们可以利用之前的结果来证明某种语言确实是不可计算的(计算困难)。我们将分两步完成此任务。首先,从层次定理我们可以得出结论,图灵机可以在指数内存(EXPSPACE)中比在多项式内存(PSPACE)中解析更多的语言。其次,我们将证明某些广义正则表达式语言在 EXPSPACE 类中是完整的,因此无法在多项式时间内甚至多项式内存中解析。

We can use previous results to show that a certain language is indeed uncomputable (computationally hard). We do this in two steps. First, we can infer from the hierarchy theorems that a Turing machine can decide more languages ​​in exponential memory (EXPSPACE) than in polynomial memory (PSPACE). Second, we will show that a certain language concerning generalized regular expressions is complete in the class EXPSPACE, and therefore cannot be decided in polynomial time or even in polynomial time.

在我们讨论泛化之前,让我们简单回顾一下定义 1.52 中介绍的正则表达式。正则表达式由原子表达式Ø 、 ε 和字母符号构建,并使用并集、串联和星号(克林闭包)的正则操作组合而成,分别用符号°和 * 编写。从问题 8.8 中我们知道,我们可以检查多项式内存中两个正则表达式的等价性。

Before we turn to generalizations, let us briefly recall regular expressions, introduced in Definition 1.52. Regular expressions are built from atomic expressions Ø , ε and alphabetic symbols, combined using the regular operations union, concatenation, and asterisk (Kleene closure), written with the symbols , ° , and *, respectively. From Task 8.8, we know that we can check the equivalence of two regular expressions in polynomial memory.

我们将证明,如果我们允许正则表达式执行比标准表达式更多的操作,则解析这些表达式的复杂性会急剧增加。令 为求幂运算。如果R是正则表达式并且k是非负整数,则符号R k相当于将R与其自身连接k。简而言之,我们将表达式R k写为R k。换句话说,

We will show that if we allow regular expressions to have more operations than the standard ones, the complexity of parsing them can increase dramatically. Let be the exponentiation operation . If R is a regular expression and k is a non-negative integer, the notation R k is equivalent to concatenating R with itself k times . For short, we will write the expression R k as R k . In other words,

除了正则正则运算之外,广义正则表达式还允许您使用求幂运算。当然,以这种方式定义的广义正则表达式会生成与正则表达式相同类别的正则语言,因为我们可以通过将其替换为多次重复的取幂表达式来消除取幂运算。让

Generalized regular expressions allow the use of exponentiation operations in addition to the regular regular operations. Of course, generalized regular expressions defined in this way generate the same class of regular languages ​​as regular expressions, since we can eliminate the exponentiation operation by replacing it with a multiple repetition of the exponentiated expression. Let

EQ REX = { Q , R : QR是等价的求幂正则表达式}。

EQ REX = { Q , R : Q and R are equivalent regular expressions with exponentiation}.

为了证明EQ REX 问题很难,我们将证明它对于 EXPSPACE 类来说是完整的。没有 EXPSPACE 完备问题可以属于 PSPACE 类,更不用说属于 P 类,否则,EXPSPACE 将等于 PSPACE,这与推论 9.7 相矛盾。

To show that the problem EQ REX is hard, we show that it is complete for the class EXPSPACE. No EXPSPACE-complete problem can belong to the class PSPACE, much less to the class P. Otherwise, EXPSPACE would be equal to PSPACE, which contradicts Corollary 9.7.

定义 9.14

Definition 9.14

语言BEXPSPACE 完备的,如果

A language B is EXPSPACE-complete if

  1. B 宇宙空间
  2. B EXPSPACE
  3. 属于 EXPSPACE 类的每种语言A都可以多项式时间约简到语言B。
  4. Every language A belonging to the class EXPSPACE is reducible in polynomial time to language B .

定理9.15

Theorem 9.15

EQ REX 语言是 EXPSPACE 完整的。

The EQ REX language is EXPSPACE-complete.

证明的概念 EQ REX 问题中,我们假设所有指数都写为二进制数。表达式的长度是它包含的符号总数。

Proof Concept In the EQ REX problem , we assume that all exponents are written as binary numbers. The length of the expression is the total number of symbols it contains.

我们将概述EQ REX问题的 EXPSPACE 类算法。为了检查两个求幂表达式是否等价,我们首先使用表达式重复来消除求幂,然后将结果表达式转换为非确定性有限自动机(NFA)。最后,我们将使用类似于示例 8.4 中的ALL NFA补码解析过程的 NFA 等价检查过程。

We sketch an algorithm of class EXPSPACE for the problem EQ REX . To check whether two exponentiation expressions are equivalent, we first use expression repetition to eliminate exponentiation, and then transform the resulting expressions into nondeterministic finite automata (NFA). Finally, we use an NFA equivalence procedure similar to the procedure for deciding the complement of the ALL NFA in Example 8.4.

为了证明EXPSPACE 类的语言A可以多项式时间约简到EQ REX问题,我们将使用第 5.1 节中介绍的计算历史约简技术。该构造类似于定理 5.13 证明中给出的构造。

To show that a language A of the class EXPSPACE is reducible in polynomial time to the problem EQ REX , we use the technique of reduction by computation history introduced in Section 5.1. This construction is similar to the construction given in the proof of Theorem 5.13.

给定语言A的图灵机M ,我们将展示多项式约简,将输入词w转换为一对表达式R 1R 2 ,当M接受w时,它们完备等价。表达式R 1R 2模拟机器M对单词w的计算。R 1表达式只是生成字母表上方的所有单词,其中包含可能出现在计算历史中的符号。R 2表达式生成不丢弃计算历史的所有单词。如果机器接受其输入,则不存在拒绝的计算历史,因此表达式R 1R 2生成相同的语言。回想一下,拒绝历史记录是机器在计算中经历的一系列配置,最终以拒绝输入词结束。有关计算历史的讨论,请参见第 220 页的第 5.1 节。

Given a Turing machine M for language A, we show a polynomial reduction that converts an input word w into a pair of expressions R 1 and R 2 , which are equivalent exactly when M accepts w . The expressions R 1 and R 2 simulate the computation of the machine M for a word w . The expression R 1 simply generates all words over the alphabet containing symbols that can appear in the computation history. The expression R 2 generates all words that are not rejecting computation histories. If the machine accepts its input word, there are no rejecting computation histories, and so the expressions R 1 and R 2 generate the same language. Recall that a rejecting computation history is the sequence of configurations that the machine goes through in the computations that end with the rejection of the input word. The discussion of the computation history can be found on page 220 of Section 5.1.

这个证明的困难在于构造表达式的大小必须是关于n 的多项式(以便减少可以在多项式时间内进行),而模拟计算的长度可以是指数的。求幂运算在这里对于用相对较短的表达式表示较长的计算非常有用。

The difficulty with this proof is that the size of the expressions being constructed must be polynomial in n (so that the reduction can proceed in polynomial time), while the computation being simulated may be exponential in length. The exponentiation operation will be useful here for representing long computations by relatively short expressions.

证明 首先,我们展示了一种非确定性算法,用于检查两个非确定性有限自动机是否不等价。

Proof We first show a nondeterministic algorithm to check whether two nondeterministic finite automata are nonequivalent.

N = "对于输入词N 1 , N 2 ,其中N 1N 2是 NFA:

N = "For input word N 1 , N 2 , where N 1 and N 2 are NFA:

  1. 在机器N 1N 2的每个初始状态中放置标记。
  2. Place tokens in each of the initial states of the machines N 1 and N 2 .
  3. 重复以下步骤 2 q 1+ q 2次,其中q 1q 2是机器N 1N 2的状态号:
  4. Repeat the following step 2 q 1 + q 2 times, where q 1 and q 2 are the numbers of states of the machines N 1 and N 2 :
  5. 非确定性地选择一个输入符号并更改机器N 1N 2状态上的标记位置,模拟它们读取该符号。
  6. Nondeterministically choose an input symbol and change the positions of the tokens on the states of the machines N 1 and N 2 , simulating that they read that symbol.
  7. 如果在任何时候一个标签被置于其中一台机器的接受状态,而同时另一台机器中的标签处于非接受状态,则接受。否则,丢弃。”
  8. If at any time the token was placed in the accepting state of one of the automata, while at the same time the token in the other automaton is in the non-accepting state, accept . Otherwise reject ”.

如果机器N 1N 2相等,则机器N显然会拒绝,因为它只有在确定其中一台机器接受另一台机器不接受的单词时才会接受。如果这些机器不等价,则某个单词可以被一台机器接受,但不能被另一台机器接受。某些此类单词的长度最多必须为 2 q 1 + q 2。否则,我们可以将这样一个最短的单词视为一系列非确定性选择。在机器状态N 1N 2上排列标记的方式只有 2 q 1+ q 2,因此在较长的单词中,标记位置必须重复。通过删除重复位置之间的单词部分,我们可以获得更短的单词。因此,N算法可以在其非确定性选择中猜测这个较短的单词并基于它接受。可以看到,N台机器工作正常。

If the machines N 1 and N 2 are equivalent, machine N will obviously reject, since it accepts only if it determines that one of the machines accepts a word that the other does not. If the machines are not equivalent, some word is accepted by one machine but not by the other. Some such word must be at most 2 q 1 + q 2 long . Otherwise, we could treat such a shortest word as a sequence of nondeterministic choices. There are only 2 q 1 + q 2 different ways to place the tokens on the states of machines N 1 and N 2 , so in the longer word the positions of the tokens would have to repeat. By deleting part of the word between the places of repetition, we could obtain a shorter such word. Thus, algorithm N can guess this shorter word among its nondeterministic choices and accept it on the basis of it. As you can see, machine N works correctly.

N算法在非确定性线性存储器中运行。因此,萨维奇定理意味着我们还有一个在O ( n 2 ) 内存中运行的确定性算法来解决这个问题。接下来,我们将使用该算法的确定性形式给出以下解析EQ REX语言↑的算法E。

Algorithm N runs on nondeterministic linear memory. Savitch's theorem therefore implies that we also have a deterministic algorithm for this problem running on O ( n 2 ) memory. In what follows, we use the deterministic form of this algorithm to give the following algorithm E for resolving the EQ REX language .

E = "对于输入词R 1 , R 2 ,其中R 1R 2是求幂正则表达式:

E = "For input word R 1 , R 2 , where R 1 and R 2 are regular expressions with exponentiation:

  1. 使用重复而不是求幂将R 1R 2转换为等效的正则表达式B 1B 2 。
  2. Convert R 1 and R 2 to equivalent regular expressions B 1 and B 2 , using repetition instead of exponentiation.
  3. 使用引理 1.55 证明中提出的过程将B 1B 2变换为等效的非确定性有限自动机N 1N 2 。
  4. Transform B 1 and B 2 into equivalent nondeterministic finite automata N 1 and N 2 using the procedure in the proof of Lemma 1.55.
  5. 使用N算法的确定性版本来确定N 1N 2是否等效。
  6. Use a deterministic version of the N algorithm to determine whether N 1 and N 2 are equivalent."

算法E显然是正确的。为了分析其内存复杂性,我们可以注意到,使用重复来代替求幂可以将表达式的长度增加 2 l倍,其中l是指数长度的总和。因此,表达式B 1B 2的长度至多为n 2 n,其中n是输入字的长度。引理1.55中的转换过程线性增加大小,因此N 1N 2自动机最多具有O ( n 2 n ) 状态。输入字大小为O ( n 2 n ) 时, N算法的确定性版本在内存中运行O (( n 2 n ) 2 ) = O ( n 2 2 2 n )。因此,EQ REX 语言是指数可判定的。

Algorithm E is obviously correct. To analyze its space complexity, we can note that using repetition to replace exponentiation can increase the length of the expression by a factor of 2l , where l is the sum of the lengths of the exponents. Thus, the expressions B 1 and B 2 have lengths at most n 2 n , where n is the length of the input word. The conversion procedure in Lemma 1.55 increases the size linearly, so the automata N 1 and N 2 have at most O ( n 2 n ) states. With input word size O ( n 2 n ) , the deterministic version of algorithm N runs in memory O ( ( n 2 n ) 2 ) = O ( n 2 2 2 n ). Thus, the language EQ REX is decidable in exponential space.

然后我们证明EQ REX 问题是 EXPSPACE 困难的。令A为运行在内存 2 ( nk )中图灵机M对某个常数k解析的语言。归约将输入单词w转换为一对正则表达式R 1R 2。表达式R 1为Δ*,其中Δ = Σ Q {#},其中ΣQ分别是磁带字母表和机器状态集M。因此,Δ 是一个包含所有可能出现在计算历史中的符号的字母表。我们将构造一个R 2表达式,该表达式生成所有不丢弃机器M对单词w的计算历史的单词。当然,当且仅当单词w 的M没有丢弃计算历史时, M才会接受。因此,当且仅当机器M接受单词w时,这两个表达式是等价的。该构造如下。

Next, we show that the problem EQ REX is EXPSPACE-hard. Let A be a language solvable by a Turing machine M operating on memory 2 ( n k ) for some constant k . The reduction transforms the input word w into a pair of regular expressions R 1 and R 2 . The expression R 1 is Δ*, where Σ and Q are the tape alphabet and the set of states of M , respectively . Δ is therefore the alphabet containing all symbols that can appear in the computation history. We construct an expression R 2 that generates all words that are not rejecting computation histories of M for word w . Of course, M accepts if and only if M has no rejecting computation histories for word w . Thus, these two expressions are equivalent if and only if M accepts word w . The construction is as follows.

机器M对单词w的丢弃计算历史是由#符号分隔的配置序列。我们将使用我们的标准配置编码方法,其中与当前状态对应的符号位于当前头位置的左侧。我们假设所有配置的长度均为 2 ( n k ),并且如果它们太短,则用空符号进行右侧填充。计算丢弃历史中的第一个配置是机器M对于w的初始配置。最后一个配置是拒绝配置。每个配置必须根据转换函数中指定的规则从前一个配置产生。

The rejecting computation history of M for a word w is a sequence of configurations separated by # symbols. We will use our standard method of encoding configurations, in which the symbol corresponding to the current state is to the left of the current head position. We assume that all configurations are of length 2 ( n k ) and are padded on the right with null symbols if they would be too short. The first configuration in the rejecting computation history is the initial configuration of M for w . The last configuration is the rejecting configuration. Each configuration must follow from the previous one according to the rules specified in the transition function.

出于多种原因,一个单词可能不是一个令人反感的计算故事:它可能不以正确的方式开始或结束,但也可能在中间的某个地方不正确。表达式R 2将等于总和R bad-start R bad-window R bad-reject no,其中每个子表达式对应于消除该单词的错误之一。

A word may not be a rejecting computation history for many reasons: it may not start or end properly, or it may be incorrect somewhere in between. The expression R 2 will be equal to the sum R bad-start R bad-window R bad-reject , where each of these subexpressions corresponds to one of the word's eliminating errors.

我们将构造R bad-start表达式来生成单词w的所有不以机器M的起始配置C 1开头的单词,如下所示。C 1的配置如下:q 0 w 1 w 2 w n #。我们将R bad-start表达式写为C 1每个部分的许多子表达式的总和:

We will construct the expression R bad-start so that it generates all words not starting with the initial configuration C 1 of machine M for word w , as follows. The configuration C 1 looks like this: q 0 w 1 w 2 w n #. We will write the expression R bad-start as a sum of many subexpressions, relating to individual parts of C 1 :

R坏开始= S 0 S 1 S n S b S #

R bad-start = S 0 S 1 S n S b S # .

表达式S 0生成所有不以q 0开头的单词。我们假设S 0等于表达式 Δ q 0 Δ*。符号Δ - q 0是表达式的缩写,该表达式是来自集合Δ中除q 0之外的所有符号的和。

The expression S 0 generates all words that do not start with q 0 . We will assume that S 0 is equal to the expression Δ q 0 Δ*. The notation Δ q 0 is a shorthand for the expression that is the sum of all the symbols from the set Δ except q 0 .

表达式S 1生成在第二位置不包含符号w 1 的所有单词。令S 1等于Δ_ delta w 1 Δ*。一般来说,对于 1 ≤ in,表达式S i为 Δ i Δ wi Δ*。这样,S i生成包含素数i位置中的任何符号、位置i +1 中的任何非w i符号以及位置i +1 之后的任何符号的所有单词。注意求幂运算的使用。事实上,求幂只是为了方便,而不是必须,因为我们可以多次重复符号 Δ而不会显着增加表达式的长度。然而,在下一个子表达式中,求幂的使用对于维持表达式的多项式大小至关重要。

The expression S 1 generates all words that do not contain the symbol w 1 in the second position. Let S 1 be equal to Δ_ delta w 1 Δ*. In general, for 1 ≤ in , the expression S i is Δ i Δ wi Δ*. In this way, S i generates all words that contain any symbols in the first i positions, any symbol other than w i in position i + 1, and any symbols after position i + 1. Note the use of the exponentiation operation. In fact, exponentiation here is a matter of convenience, not necessity, since we could repeat the symbol Δ i times without increasing the length of the expression significantly. However, in the next subexpression, the use of exponentiation is crucial to maintaining the polynomial size of the expression.

表达式S b从位置n + 2 到 2( n k )之间的某个点生成不包含空白符号的所有单词。为此,我们可以创建子表达式S n +2 , …, S 2( n k ),但是R坏开始表达式将具有指数长度。相反,我们将定义

The expression S b generates all words that do not contain a blank symbol from some point between positions n + 2 and 2( n k ). We could create subexpressions S n +2 , …, S 2( n k ) for this purpose , but then the expression R bad-start would have exponential length. Instead, we define

S b = Δ n + 1 ε) (2 ( nk ) ) Δ Δ*。

S b = Δ n + 1 ε) (2 ( nk ) ) Δ Δ*.

因此,S b生成的单词包含前n + 1 个位置中的任何符号、随后t 个位置中的任何符号,其中t可以从 0 到 2 ( n k ) − n − 2变化,以及除了空符号之外的任何符号下一个位置。

So S b generates words containing any symbols in the first n + 1 positions, any symbols in the next t positions, where t can vary from 0 to 2 ( n k ) − n − 2 , and any symbol except the blank in the next position.

最后,S #表达式生成位置2 ( nk ) +1不包含#符号的所有单词。我们定义

Finally, the expression S # generates all words that do not contain the symbol # in position 2 ( n k ) + 1. We define

S #(2 ( nk ) ) Δ- # Δ*。

S # = Δ (2 ( nk ) ) Δ −# Δ*.

一旦我们完成了R bad-start 的构建,我们就可以继续最后一部分,即R bad-reject表达式。它生成所有未正确结尾的单词。换句话说,它生成不包含拒绝配置的单词。每个拒绝配置都包含状态q拒绝,所以我们将定义

After we have finished constructing R bad-start, we can move on to the final part, the expression R bad-reject . It generates all words that do not end in the appropriate way. In other words, it generates words that do not contain a rejecting configuration. Every rejecting configuration contains a state q reject , so we define

R不良拒绝= Δ* q拒绝

R bad-reject = Δ* q reject .

所以R z e-reject生成所有不包含qreject单词。

So R e-reject generates all words that do not contain q reject .

最后,我们将构建一个R坏窗口表达式,该表达式生成所有单词,其中一个配置不能以有效的方式导致下一个配置。回想一下,在库克-莱文定理的证明中,我们指出,当且仅当第一个配置的每三个连续符号生成第二个配置中相应的三个符号时,一个配置正确地导致下一个配置。因此,如果某个配置与前一个配置不相符,则可以通过分析相应的六个符号来发现错误。我们将使用这个想法来构造R坏窗口表达式:

Finally, we construct the expression R bad-window , that is, the expression that generates all the words in which one configuration does not correctly lead to the next configuration. Recall that in the proof of the Cook–Levin theorem we stated that one configuration correctly leads to the next if and only if every three consecutive symbols of the first configuration generate corresponding three symbols in the second configuration. Thus, if a certain configuration does not follow from the previous one, the error can be detected by analyzing the corresponding six symbols. We use this idea to construct the expression R bad-window :

其中 bad( abc , def ) 表示根据传递函数,三元组abc不会产生三元组def 。对属于 Δ 的所有符号abcdef执行求和。下图显示了这些符号在计算历史记录中的位置。

where bad( abc , def ) means that the triple abc does not give rise to the triple def according to the transition function. The sum is performed over all symbols a , b , c , d , e and f belonging to Δ. The figure below shows the distribution of these symbols in the computation history.

9.16

相邻配置中的对应位置

Figure 9.16

Corresponding positions in adjacent configurations

为了计算R 2表达式的长度,我们将确定其中出现的指数的长度。我们可以注意到这里有几个值为 2 ( n k )阶的指数,它们的二进制总长度为O ( n k )。因此整个R 2表达式的长度是关于n 的多项式。

To calculate the length of the expression R 2 , we determine the lengths of the exponents that appear in it. We can see that there are several exponents of order 2 ( n k ) , and their total length in binary notation is O ( n k ). Hence, the length of the entire expression R 2 is polynomial in n .

9.2

相对化

9.2

Relativization

EQ REX 问题计算困难的证明是基于对角化方法。为什么我们不以同样的方式表明SAT问题很难呢?潜在地,我们似乎可以使用对角化来证明非确定性多项式时间图灵机可以解析我们可以证明不属于 P 的语言。在本节中,我们介绍一种相对化方法,它强烈表明问题PNP 无法使用对角化证明来解决。

The proof that the EQ REX problem is computationally hard relies on the method of diagonalization. Why don't we show in the same way that the SAT problem is hard? Potentially, it seems that we could use diagonalization to show that a nondeterministic polynomial-time Turing machine can decide a language that we can prove is not a member of P. In this section, we introduce the method of relativization , which gives strong indications that the P versus NP problem cannot be solved by proof by diagonalization.

在相对化方法中,我们将通过让图灵机“免费”访问某些信息来修改我们的计算模型。根据这些信息的内容,图灵机将能够比以前更容易地解决某些问题。

In the relativization method, we modify our model of computation by giving the Turing machine access to some information “for free.” Depending on what that information is, the Turing machine will be able to solve certain problems much more easily than before.

例如,假设我们赋予图灵机一步解决任意大小逻辑公式的可满足性问题的能力。它如何实现并不重要——我们可以想象我们将一个神奇的“黑匣子”附加到提供这种可能性的机器上。我们将这个黑匣子称为预言机,以强调它不必对应于任何物理(物理上可实现的)设备。显然,这样的机器可以使用预言机在多项式时间内解决 NP 类的任何问题,无论 P 类是否等于 NP,因为 NP 类的每个问题都可以在多项式时间内简化为可满足性问题。我们说这样的图灵机执行与可满足性问题相关的计算,术语“相对化”就来自于此。

For example, suppose we give a Turing machine the ability to solve in one step the satisfiability problem for logical formulas of arbitrary size. It does not matter how this is done – we can imagine that we attach to the machine a magical “black box” that provides this ability. We call this black box an oracle , to emphasize the fact that it does not have to correspond to any physical device (physically realizable). It is obvious that such a machine can use the oracle to solve in polynomial time any problem in the class NP, regardless of whether the class P is equal to NP, since every problem in the class NP is reducible in polynomial time to a satisfiability problem. We say that such a Turing machine computes relative to (relative to) the satisfiability problem, whence the term relativization .

一般来说,预言机可以解决任何语言,而不仅仅是可满足性问题。预言机允许图灵机检查语言从属关系,而无需自己计算答案。我们稍后将正式确定这个概念。回想一下,我们已经在 6.3 节中介绍了预言机。我们在那里根据问题的不可解决程度对问题进行分类。现在我们将使用预言机来更好地理解对角化方法的强大功能。

In general, an oracle can correspond to any language, not just the satisfiability problem. An oracle allows a Turing machine to check for language membership without having to compute the answer itself. We will formalize this notion in a moment. Recall that we introduced oracles in Section 6.3. We used them there to classify problems according to their degree of unsolvability. We now use oracles to better understand the power of diagonalization.

定义9.17

Definition 9.17

语言A的预言机是一个可以确定给定单词是否属于语言A的设备。具有预言机M A的图灵机是经过修改的图灵机,具有查询语言A的预言机的附加能力。每当M A在特殊的预言机磁带上写入一个单词,在一步计算中,它会收到该单词是否属于语言A的答案。

An oracle for language A is a device that can determine whether a given word w belongs to language A . A Turing machine with an oracle M A is a modified Turing machine with the additional ability to query the oracle for language A . Whenever M A writes a word onto a special oracle tape , in one computational step it receives an answer as to whether the word belongs to language A .

令 P A为具有语言A预言机的图灵机可在多项式时间内判定的语言类别。我们以类似的方式定义NP A类。

Let P A be the class of languages ​​decidable in polynomial time by a Turing machine with an oracle for language A . Analogously, we define the class NP A .

9.18

Example 9.18

正如我们之前提到的,可满足性问题的多项式时间计算包含整个 NP 类。换句话说,NP P SAT。此外,还有 coNP P SAT,因为类 P SAT作为计算复杂度的确定性类,由于补集而被封闭。

As we mentioned earlier, polynomial-time computation with respect to the satisfiability problem contains the entire class NP. In other words, NP P SAT . Moreover, also coNP P SAT , since the class P SAT , as a deterministic computational complexity class, is closed under complement.

9.19

Example 9.19

正如 P SAT类包含我们有强有力的证据表明它们不属于 P 类的语言一样,NP SAT类包含我们有强有力的证据表明它们不属于 NP 类的语言。我们在第 328 页的问题 7.46 中定义的MIN-FORMULA语言的补集就是这种语言的一个示例。

Just as the class P of SAT contains languages ​​for which we are convinced that they are not members of the class P, the class NP of SAT contains languages ​​for which we have strong reasons that they are not members of the class NP. The complement of the language MIN-FORMULA , which we defined in Problem 7.46 on page 328, is an example of such a language.

MIN-FORMULA问题似乎不属于 NP 类(尽管这一事实的证据未知)。然而,MIN-FORMULA问题属于 NP SAT ,因为在多项式时间内运行的SAT语言的非确定性预言机图灵机可以通过以下方式检查公式Φ是否属于该语言。首先,两个逻辑公式的非等价问题在 NP 类中是可解的,因此等价问题属于 coNP 类,因为非确定性机器可以猜测两个公式具有不同值的分配。其次,针对MIN-FORMULA问题的非确定性预言机可以猜测一个更小的等价公式,使用SAT预言机检查它是否确实等价,如果是则接受它。

The MIN-FORMULA problem , it seems, does not belong to NP (although a proof of this fact is not known). Nevertheless, the MIN-FORMULA problem belongs to NP SAT , since a nondeterministic Turing machine with an oracle for the language SAT running in polynomial time can check whether the formula Φ belongs to that language in the following way. First, the non-equivalence problem for two Boolean formulas is solvable in NP, and thus the equivalence problem belongs to coNP, since the nondeterministic machine can guess an assignment for which the two formulas have different values. Second, a nondeterministic Turing machine with an oracle for the MIN-FORMULA problem can guess a smaller equivalent formula, use the SAT oracle to check whether it is indeed equivalent, and accept if it is.

对角化方法的适用局限性

Limitations of the applicability of the diagonalization method

下一个定理显示了语言A和 B的预言,可以证明 P A和 NP A不同,而 P B和 NP B相等。这两个预言很重要,因为它们的存在表明使用对角化方法不太可能找到P与NP 问题的解决方案。

The next theorem shows oracles for languages ​​A and  B such that it can be proven that P A and NP A are distinct, and P B and NP B are equal. These two oracles are important because their existence indicates that it is unlikely that a solution to the problem P versus NP can be found using the diagonalization method.

对角化方法的核心是用一台图灵机模拟另一台图灵机。模拟的执行方式是模拟机器可以确定另一台机器的行为,然后自己执行另一个动作。我们假设这两台图灵机都有相同的预言机。然后,每当模拟机查询预言机时,模拟器都会执行相同的操作,因此模拟是相同的。因此,当两台机器具有相同的预言机时,使用对角化方法证明的任何关于图灵机的定理仍然成立。

In essence, the diagonalization method involves simulating one Turing machine by another. The simulation is performed in such a way that the simulating machine can determine the behavior of the other machine and then perform a different action. Suppose that both of these Turing machines have identical oracles. Then, whenever the simulated machine queries the oracle, the simulator does the same, so the simulation proceeds in the same way. Consequently, any theorem about Turing machines proved using the diagonalization method is still true when both machines have the same oracle.

特别是,如果我们可以使用对角化来证明 P 类和 NP 类是不同的,那么它们对于任何预言机来说仍然是不同的。然而,P B和 NP B相等,因此这个结论是错误的。由此可见,对角化不足以区分这些类别。类似地,基于简单模拟的任何证明都不能证明这些类是相等的,因为相同的证明将表明它们在任何相对化方面都是相同的,而 P A和 N A是不同的。

In particular, if we could prove by diagonalization that the classes P and NP are distinct, they would still be distinct with respect to any oracle. However, P B and NP B are equal, so this conclusion is false. It follows that diagonalization is not sufficient to distinguish these classes. Similarly, no proof based on simple simulation can show that these classes are equal, since the same proof would show that they are the same with respect to any relativization, while P A and NP A are distinct.

定理9.20

Theorem 9.20

  1. 存在一个预言机A,其中P A N A。
  2. There exists an oracle A for which P A NP A .
  3. 存在一个预言B,其中 P B = NP B。
  4. There exists an oracle B for which P B = NP B .

证明的概念预言机B 的构造很简单。 B是任何 PSPACE 完备问题就足够了,例如 TQBF。

The Concept of Proof The construction of the oracle B is straightforward. It suffices that B be any PSPACE-complete problem, such as TQBF.

我们将通过构建来展示预言机A。我们将设计语言A,使得可以证明属于NP A类的某种语言L A需要暴力算法,因此L A不能属于P A类。因此我们可以得出结论:P A N A。在构建中,我们将依次包含所有多项式时间预言机,并确保它们都不能解析LA语言

We will show an oracle A by construction. We will design a language A in such a way that it can be proven that a certain language L A belonging to the class NP A requires a brute-force algorithm, and therefore L A cannot belong to the class P A . Hence we can conclude that P A NP A . In the construction we consider in turn all polynomial-time oracle machines and ensure that none of them decides the language L A .

证明 B为TQBF的语言。然后得出以下结论:

Proof Let B be a TQBF language . Then the following inclusions hold:

包含 1 的发生是因为我们可以将具有多项式时间预言机的非确定性图灵机转换为非确定性多项式时间机,该机计算 TQBF 问题的答案不是使用预言机。包含 2 由 Savitch 定理得出。遏制 3 得到满足,因为TQBF语言是 PSPACE 完备的。所以我们可以得出结论 P TQBF = NP TQBF

Containment 1 holds because we can transform a nondeterministic Turing machine with a polynomial-time oracle into a nondeterministic polynomial-time machine that computes answers to questions about the TQBF language instead of using the oracle. Containment 2 follows from Savitch's theorem. Containment 3 holds because the TQBF language is PSPACE-complete. We can therefore conclude that P TQBF = NP TQBF .

现在我们将展示如何构建预言机A。对于任何预言机A,L A是语言A中存在相同长度单词的所有单词的集合。所以

We now show how to construct an oracle A . For any oracle A, let L A be the set of all words for which there is a word of the same length in language A. Therefore

L A = { w : x A [ | x |=|| ]}。

L A = { w : x A [ | x |=| in | ]}.

当然,对于任意语言A,语言L A属于NP A类。

Obviously, for any language A, the language L A belongs to the class NP A .

为了证明语言L A不属于类P A,我们将语言A设计如下。令M 1M 2、... 成为在多项式时间内运行的所有预言机图灵机的列表。为简单起见,我们可以假设机器M i在时间n i内运行。我们将分阶段进行构建,其中阶段i负责语言A的部分,确保MA不会解析语言L A。当构建语言A时,我们将声明某些单词属于A,而其他单词则不属于 A。在每个阶段,我们只会确定有限数量的单词的状态。一开始,没有任何单词在语言 A 中具有特定的地位。我们从阶段i开始。

To show that the language L A does not belong to the class P A , we design the language A as follows. Let M 1 , M 2 , … be a list of all polynomial-time Turing machines with an oracle. For simplicity, we can assume that the machine M i runs in time n i . We perform the construction in phases, where phase i is responsible for the part of the language A that ensures that M i A does not resolve the language L A . In constructing the language A , we will declare that some words belong to A and others do not. In each phase, we will specify the status of only a finite number of words. Initially, no word has a specific status in the language A. We start with phase i .

第一阶段到目前为止,我们已经声明了有限数量的单词属于或不属于语言A。我们选择n大于这些单词中任何一个的长度,并且足够大,使得 2 n大于ni 机器Mi的运行时间。我们将展示如何扩展有关语言A 的信息,以便机器M i A接受单词 1 n当且仅当该单词不属于语言L A时。

Phase i . So far we have declared for a finite number of words that they are or are not members of language A . We choose n greater than the length of any of these words and large enough so that 2 n is greater than n i , the running time of machine M i . We will show how to extend our information about language A so that machine M i A accepts word 1 n if and only if that word is not a member of language L A .

我们运行机器M i输入单词 1 n并向预言机回答问题,如下所示。如果机器M i请求一个状态已经确定的单词y ,我们根据这个状态进行响应。如果单词y的状态尚未确定,我们对问题回答“否”并声明单词y不属于A。我们模拟机器M继续直到它停止。

We start the machine M i for input word 1 n and answer questions to the oracle as follows. If the machine M i asks for a word y whose status has already been determined, we answer according to that status. If the status of word y is not yet determined, we answer NO to the question and declare that word y does not belong to A . We continue the simulation of machine M i until it stops.

我们从机器M i的角度来看这种情况。如果它发现一个长度为n的单词属于语言A,它应该接受它,因为这样它就知道单词1n属于L A。如果M i确定所有长度为n的单词不属于语言A,则它应该拒绝,因为这样它就知道单词 1 n不属于语言L A。然而,没有足够的时间来询问长度为n的所有单词,并且我们对每个问题都回答“否”。当机器M i停止并必须决定是否接受或拒绝输入单词时,它没有足够的信息来决定哪个答案是正确的。

Let's look at this situation from the perspective of machine M i . If it finds a word of length n that belongs to language A , it should accept, since it then knows that word 1 n belongs to language A . If M i determines that all words of length n do not belong to language A , it should reject, since it then knows that word 1 n does not belong to language L A . However, it does not have enough time to ask for all words of length n , and the answer to each question that is asked is NO. When machine M i stops and must decide whether to accept or reject the input word, it does not have enough information to decide which answer is correct.

我们的目标是确保机器做出的决定是正确的。我们将通过观察所做的选择并扩展语言A以使相反的陈述成立来做到这一点。特别地,如果机器M i接受单词 1 n,那么我们声明长度为n的所有其他单词不属于语言 A,因此我们确定单词 1 n不属于语言L A。如果机器M i拒绝 1 n ,那么我们找到机器M i在运行时没有查询到的长度为n的单词,并且我们声明该单词属于语言A,从而保证单词 1 n属于语言L A。这样的单词一定存在,因为机器M i走了n i步,小于 2n (长度为n的单词总数) 。不管怎样,我们保证机器MA不会解析语言L A

Our goal is to guarantee that the decision made by the machine is not correct. We do this by observing the decision being chosen and extending language A so that the converse is true. In particular, if machine M i accepts a word 1 n , then we declare that all other words of length n do not belong to language  A , and thus define that word 1 n does not belong to language L A . If machine M i rejects 1 n , then we find a word of length n that machine M i did not ask for during its run, and we declare that this word belongs to language A , thus guaranteeing that word 1 n belongs to language L A . Such a word must exist, since machine M i takes n i steps, which is less than 2 n , the total number of words of length n . In either case, we guarantee that machine M i A does not decide language L A .

我们通过声明任何长度不大于n的单词(此时其状态尚未确定)不属于语言A来结束第 1 阶段。完成 i 阶段后我们进入i +1 阶段。

We end phase 1 by declaring that any word of length no greater than n whose status is not determined at this point does not belong to language A . After completing phase i, we move on to phase i + 1.

因此,我们已经证明,在多项式时间内运行的语言 A 的图灵预言机无法解析语言L A,从而证明了该定理。

We have thus shown that no Turing machine with an oracle for language A that runs in polynomial time can resolve language L A , which proves the theorem.

总之,相对化方法告诉我们,为了能够解决 PNP 问题,我们必须分析计算,而不仅仅是模拟它们。在第 9.3 节中,我们提出了一种可以引导我们进行此类分析的方法。

In summary, the method of relativization tells us that in order to solve the P versus NP problem, we need to analyze the computations, not just simulate them. In Section 9.3 we present an approach that can lead us to such an analysis.

9.3

电路复杂度

9.3

Circuit Complexity

计算机由称为数字电路的互连电子元件组成。我们可以用数字电路的理论等效物(称为逻辑电路或网络)来模拟图灵机等理论模型。将图灵机与逻辑电路耦合有两个目的。首先,研究人员发现电路是尝试解决 PNP 问题及相关问题的便捷计算模型。其次,这些电路使我们能够提供库克-莱文定理的另一种证明,即SAT问题是 NP 完备的。在本节中,我们将解决这两个问题。

Computers are made of interconnected electronic components called digital circuits . We can simulate theoretical models such as Turing machines with theoretical analogues of digital circuits, called logical circuits or networks . The association of Turing machines with logical circuits has two goals. First, researchers believe that circuits are a convenient computational model for attempting to attack the P versus NP problem and related questions. Second, circuits provide an alternative proof of the Cook–Levin theorem that the SAT problem is NP-complete. In this section, we address both of these issues.

定义9.21

Definition 9.21

逻辑电路是逻辑门通过电线连接的输入的集合。不允许循环。逻辑门有三种形式:与门、或门和非门,如图 9.22 所示。

A logic circuit is a collection of logic gates and inputs connected by wires . Cycles are not allowed. Logic gates come in three forms: AND gates, OR gates, and NOT gates, shown schematically in Figure 9.22.

9.22

AND、OR 和 NOT 门

Figure 9.22

AND, OR, and NOT gates

逻辑电路中的导线携带逻辑值0和1。门是处理AND、OR和NOT逻辑功能的简单处理器。如果两个输入上的值都等于 1,则 AND 函数返回输出值 1,其他情况下返回 0。如果两个输入都为 0,则 OR 函数返回 0,否则返回 1。NOT 函数返回输入的倒数;也就是说,如果输入为 0,则返回 1;如果输入为 1,则返回 0。输入标记为x 1 , ..., x n。其中一扇门是指定的出口门。下图显示了逻辑电路的示例。

The wires in a logic circuit carry the logical values ​​0 and 1. Gates are simple processors that process the logical functions AND, OR, and NOT. The AND function returns an output of 1 if both inputs are 1, and 0 otherwise. The OR function returns 0 if both inputs are 0, and 1 otherwise. The NOT function returns the inverse of the input; that is, it returns 1 if it has an input of 0, and 0 if it has an input of 1. The inputs are labeled x 1 , …, x n . One of the gates is the designated output gate . The following figure shows an example of a logic circuit.

9.23

逻辑电路示例

Figure 9.23

Example of a logic circuit

逻辑电路根据分配给输入变量的值计算输出值,通过电线传播这些值并计算与适当的门相关的函数,直到输出门具有分配的值。下图显示了计算给定输入值的输出值的逻辑电路。

The logic circuit calculates an output value from the values ​​assigned to the input variables, propagating these values ​​across the wires and calculating the functions associated with the appropriate gates until the output gate has a value assigned. The next figure shows a logic circuit calculating an output value for the given input values.

9.24

逻辑电路中的计算示例

Figure 9.24

Example of calculation in a logical circuit

我们使用函数来描述输入和输出之间逻辑电路的行为。我们将函数f C 分配给具有n 个输入变量的逻辑电路C:{ 0 , 1 } n { 0 , 1 }。如果电路C在其输入变量x 1 , …, x n被赋值为值a 1 , …, a n时返回值b ,则我们写f C ( a 1 , …, a n ) = b。我们说电路C计算函数f C。有时我们也会考虑具有多个输出门的逻辑电路。在这种情况下,电路计算一个具有k 个输出位的函数,即具有一组值 { 0 , 1 } k的函数。

We use functions to describe the behavior of a logical circuit between input and output. A logical circuit C with n input variables is assigned a function f : { 0 , 1 } n { 0 , 1 }. We write that f C ( a 1 , …, a n ) = b , if the circuit C returns the value b when its input variables x 1 , …, x n are assigned the values ​​a 1 , …, a n . We say that the circuit C computes the function f C . Sometimes we will also consider logical circuits that have multiple output gates. In such a case, the circuit computes a function with k output bits, that is, a function with the set of values ​​{ 0 , 1 } k .

9.25

Example 9.25

如果输入变量中有奇数个 1,则具有n 个输入的奇偶校验函数奇偶校验n : { 0 , 1 } n { 0 , 1 } 返回 1。图 9.26 所示的电路计算奇偶校验函数4,它是四个变量的奇偶校验函数。

The parity function with n inputs parity n : { 0 , 1 } n { 0 , 1 } returns 1 if there is an odd number of 1s among the input variables. The circuit in Figure 9.26 computes the parity function 4 , which is a parity function of four variables.

9.26

计算四个变量的奇偶校验函数的逻辑电路

Figure 9.26

Logic circuit calculating the parity function for four variables

如果我们可以使用 { 0 , 1 } 字母表适当地对语言进行编码,我们计划使用逻辑电路来测试语言成员资格。一个立即引人注目的问题是,特定电路只能处理固定长度(输入数量)的输入,而语言可以包含不同长度的单词。因此,我们将使用一整套电路,每个电路对应一个输入字长,而不是使用单个电路来检查语言成员资格。我们将在下面的定义中形式化这个概念。

We plan to use logic circuits to test for language membership, if we can encode these languages ​​appropriately using the alphabet { 0 , 1 }. An immediately noticeable problem arises from the fact that a particular circuit can only handle inputs of a fixed length (the number of inputs), while the language can contain words of different lengths. So instead of using a single circuit to test for language membership, we will use a whole family of circuits for this purpose, one for each input word length. We formalize this notion in the following definition.

定义9.27

Definition 9.27

电路族C是电路的无限列表(C 0C 1C 2 ……),其中电路C n具有n 个输入变量。我们说C在字母表 { 0 , 1 } 上解析了语言A,如果对于每个单词ww A当且仅当C n ( w ) = 1,其中n是单词w的长度。

The family of circuits C is an infinite list of circuits ( C 0 , C 1 , C 2 , …), where a circuit C n has n input variables. We say that C resolves a language A over the alphabet { 0 , 1 } if for each word w , w A if and only if C n ( w ) = 1, where n is the length of word w .

电路的大小是它包含的门的数量。如果两个电路具有相同的输入变量并且为这些变量的每次赋值返回相同的值,则它们是等效的。如果不存在更小的等效周长,则周长具有最小尺寸。最小化电路问题在电路设计中有着明显的应用,但在一般情况下很难解决。即使检查给定电路是否最小的问题在 P 类甚至 NP 类中似乎也不是可解决的问题。列表中的每个C i都是最小电路,则电路族是最小电路系列( C 0 C 1 C 2 ……)大小相关的复杂性是f : N N的函数,其中f ( n ) 是电路C n的大小。如果我们明确讨论的是尺寸,我们将简单地提及电路系列的复杂性,而不是相对于尺寸的复杂性。

The size of a circuit is the number of gates it contains. Two circuits are equivalent if they have the same input variables and return the same value for each assignment of those variables. A circuit has minimal size if there is no smaller equivalent circuit. The problem of minimizing circuits has obvious applications in their design, but it is very difficult to solve in the general case. Even the problem of checking whether a given circuit is minimal does not seem to be a solvable problem in the class P or even in the class NP. A family of circuits is minimal if each C i in the list is a minimal circuit. The size complexity of a family of circuits ( C 0 , C 1 , C 2 , …) is a function f : N N , where f ( n ) is the size of the circuit C n . We will simply refer to the complexity of the family of circuits rather than the size complexity if it is clear that we are talking about size.

电路深度是从输入变量到输出门的最长路径的长度(电线数量)。以类似于尺寸的方式定义最小深度电路和最小深度电路族,以及相对于电路族深度的复杂性。我们将在第 10.5 节并行计算中主要处理与深度有关的电路复杂性。

The depth of a circuit is the length (number of wires) of the longest path from an input variable to an output gate. We define minimum-depth circuits and minimum-depth circuit families, and the depth complexity of a circuit family in a way analogous to size. We will deal mainly with the depth complexity of a circuit in Section 10.5 on parallel computing.

定义9.28

Definition 9.28

一种语言按大小划分的电路复杂度是该语言的最小电路族的大小复杂度。语言深度而导致的电路复杂性也被类似地定义,但使用深度而不是大小。

The circuit complexity with respect to size for a language is the size complexity of the minimal circuit family for that language. The circuit complexity with respect to depth for a language is defined analogously, but using depth instead of size.

9.29

Example 9.29

我们可以轻松地概括例 9.25,以显示计算 n 个变量奇偶校验函数的电路,其中包含O ( n ) 个异或门,其中 XOR 是奇偶校验2函数,然后用两个非门、两个与门和两个门来实现每个异或门。一个或门,如前面的示例所示。

We can easily generalize Example 9.25 to show circuits that compute parity functions of n variables, containing O ( n ) XOR gates, where XOR is a parity function of 2 , and implement each XOR gate with a circuit of two NOT gates, two AND gates, and one OR gate, as in the earlier example.

A是由包含奇数个 1 的单词组成的语言。那么A 的电路复杂度为O ( n )。

Let A be a language composed of words that contain an odd number of ones. Then A has circuit complexity with respect to size O ( n ).

一种语言的电路复杂度与该语言的时间复杂度有关。任何时间复杂度低的语言也将具有低电路复杂度,如以下定理所示。

The circuit complexity of a language is related to the time complexity of that language. Any language with a small time complexity will also have a small circuit complexity, as the following theorem shows.

定理9.30

Theorem 9.30

t : N N为t ( n ) ≥ n的函数。如果A TIME( t ( n )),则语言A的电路复杂度为O ( t 2 ( n ))。

Let t : N N be a function for which t ( n ) ≥ n . If A TIME( t ( n )), then the language A has circuit complexity O ( t 2 ( n )).

这个定理允许我们通过尝试找到一种属于 NP 类且其电路复杂度大于多项式的语言来解决证明 P NP的问题。

This theorem allows us to approach the problem of proving that P NP by trying to find a language in the class NP whose circuit complexity is greater than polynomial.

证明的概念 M是在时间t ( n )解析A 的图灵机。 (为简单起见,我们忽略O ( t ( n ))中的常数因子,即机器M的实际运行时间)。对于每个n,我们构造一个电路Cn来模拟长度为n的输入字的M。我们将C n电路的门按行排列,每个门对应机器M对长度为n的输入字进行计算的t ( n ) 个步骤。每行门代表机器M在相应步骤的配置每行都通过电线连接到前一行,以便可以根据前一行的配置计算当前配置。我们将修改机器M,使其输入单词使用字母表 {0,1} 书写。此外,我们更改了 M 机器,以便在接受它之前,它将磁头移动到磁带的左端,并在该单元格中写入符号。这样我们就可以将电路最后一行的门指定为输出门。

Concept of the Proof Let M be a Turing machine that decides A in time t ( n ). (For simplicity, we ignore the constant factor in O ( t ( n )), the actual running time of M .) For each n, we construct a circuit C n that simulates M for input words of length n . We arrange the gates of C n in rows, one for each of the t ( n ) steps of M 's computation for an input word of length n . Each row of gates represents the configuration of M at the corresponding step. Each row is connected by wires to the previous row so that it can compute the current configuration from the configuration of the previous row. We modify M so that its input word is written using the alphabet {0,1}. Furthermore, we modify M so that just before accepting, it moves the head to the left end of the tape and writes the symbol in that cell. This way we can designate the gate in the last line of the circuit as the output gate.

证明 M = ( Q , Σ , Г , δ, q 0 , q Accept , q Reject )为在时间t ( n )解析语言A的机器,并设w为长度为n的输入词。我们将机器M对于单词w的定义为表t ( n ) × t ( n ),其行是机器M的配置。表格的顶行单词w的初始配置M第 i包含第 i步计算中的机器配置

Proof Let M = ( Q , Σ , Γ , δ, q 0 , q accept , q reject ) be a machine resolving language A at time t ( n ) and let w be an input word of length n . We define the tableau of machine M for word w as the table t ( n ) × t ( n ) whose rows are configurations of machine M . The top row of the tableau contains the initial configuration of M for word w . The i -th rowcontains the configuration of the machine at the i -th computation step.

为了方便起见,我们将稍微改变一下这个证明中表示配置的方式。我们将使用一个复合字符来表示状态和头下的符号,而不是第 168 页描述的旧格式,其中状态出现在头部读取的符号的左侧。例如,如果机器M处于状态q,磁带包含单词1011,并且磁头正在读取左侧的第二个符号,那么在旧格式中,这将写为1q011,但在新格式中,它将是1 q0 11 - 复合字符q0代表状态q,以及符号0,即头部下方的符号。

For convenience, in this proof we will change the way we represent the configuration slightly. Instead of the old format described on page 168, where the state appeared to the left of the symbol being read by the head, we will represent the state and the symbol under the head as a single composite character. For example, if machine M is in state q , the tape contains the word 1011 , and the head is reading the second symbol from the left, this would be written in the old format as 1q011 , and in the new format it would be 1 q0 11 — the composite character q0 represents both the state q and the symbol 0 , the symbol under the head.

每个条目可以包含一个磁带符号(字母元素Γ)或状态和磁带符号的组合(元素Q × Γ)。表格第 i第 j列的值将被写为单元格[ i , j ]。表格的顶行由包含初始配置的单元[1, 1], ...,单元格[1, t ( n )] 组成。

Each entry in the tableau can contain either a tape symbol (an element of the alphabet Γ ) or a combination of a state symbol and a tape symbol (an element of Q × Γ ). The value in the i -th row and j -th column of the tableau is written as cell [ i , j ]. The top row of the tableau is therefore composed of cells cell [1, 1], …, cell [1, t ( n )] containing the initial configuration.

在定义图灵机M 的画面时,我们做出两个假设。首先,正如我们在证明概念中提到的,M机仅接受磁头位于磁带最左侧单元且该单元包含符号⊔ 的情况。其次,一旦机器M停止,它就会保持不变的配置。通过检查表格最后一行最左边的单元格[ t ( n ) , 1],我们可以确定机器M是否接受了输入单词。下图显示了机器M对于输入字 0010的表片段。

In defining the tableau for a Turing machine M, we make two assumptions. First, as mentioned in the proof concept, M accepts only when the head is in the leftmost cell of the tape and that cell contains the symbol . Second, once M stops, it remains in the same configuration. By examining the leftmost cell of the last row of the tableau, cell [ t ( n ), 1], we can determine whether M has accepted the input word. The following figure shows a fragment of M 's tableau for input word 0010.

9.31输入 0010 的机器M

的表格

Figure 9.31

Tableau of machine M for input 0010

每个单元格的内容由前一行中的特定单元格确定。知道cell [ i −1, j −1]、cell [ i −1, j ]和cell [ i −1, j +1]的值,我们可以根据cell [ i , j ]的值得到关于机器M的传递函数。下图显示了图 9.31 中的放大部分。前三个符号 0、0 和 1 是无状态磁带符号,因此下一行中间的符号仍必须为 0,如图所示。

The contents of each cell are determined by the specified cells in the previous row. Given the values ​​of cell [ i − 1, j − 1], cell [ i − 1, j ], and cell [ i − 1, j + 1], we can obtain the value of cell [ i , j ] from the transition function of machine M . The figure below shows a magnified fragment of the tableau of Figure 9.31. The top three symbols, 0, 0, and 1, are tape symbols with no states, so the middle symbol must still have the value 0 in the next row, as shown.

我们现在可以开始构建电路Cn。它将包含每个表格单元格的多个门。这些门根据前一行中影响给定单元格的三个单元格的值来计算给定单元格的值。

We can now begin constructing the circuit C n . It will contain several gates for each cell of the tableau. These gates calculate the value of a given cell based on the values ​​of the three cells in the previous row that affect it.

为了帮助描述设计,我们将在电路中添加灯以显示电路中某些门的输出。这些灯仅用于说明目的,不会影响电路的操作。

To make it easier to describe the construction, we will add lamps to the circuit showing the output of some of the circuit gates. These lamps are for illustrative purposes only and do not affect the operation of the circuit.

k为集合Г ( Q × Г )的元素数量。我们将为表格中的每个单元格创建k 个灯光 - 每个元素Γ一个,每个元素 ( Q × Γ ) 一个 - 总共kt 2 ( n ) 个灯光。我们将这些灯表示[ i , j , s ],其中 1 ≤ i , jt ( n ) 且s Г ( Q × Г )。单元格中的灯的状态指示该单元格的内容。如果[ i , j , s ] 点亮,则单元格[ i , j ] 包含符号s。当然,在正确构造的电路中,任何单元中只能点亮一盏灯。

Let k be the number of elements of the set Γ ( Q × Γ ). We will create k lights for each cell in the tableau – one for each element of Γ and one for each element of ( Q ​​× Γ ) – a total of kt 2 ( n ) lights. We will denote these lights light [ i , j , s ], where 1 ≤ i , jt ( n ) and s Γ ( Q × Γ ). The state of the lights in a cell indicates the contents of that cell. If light [ i , j , s ] is lit, then cell [ i , j ] contains the symbol s . Of course, in a properly constructed circuit, only one light can be lit in any cell.

让我们选择这些灯光之一 - 例如,单元格[ i , j ]中的灯光[ i , j , s ] 。如果单元格包含s符号,则该灯应亮起。考虑三个可以影响单元格[ i , j ] 的单元格,并尝试确定它们的哪些设置可以导致单元格[ i , j ]包含s。这可以通过检查传递函数 δ 来确定。

Let's pick one of these lights—for example, light [ i , j , s ] in cell [ i , j ] . This light should be lit if the cell contains the symbol s . Let's consider a triplet of cells that can affect cell [ i , j ], and try to determine which of their settings can cause cell [ i , j ] to contain s . This can be determined by examining the transfer function δ.

假设如果cell [ i −1, j −1]、cell [ i −1, j ]和cell [ i −1, j +1]分别包含值abc,则根据传递函数 δ cell [ i , j ] 包含s。我们将以这样的方式连接电路,当[ i − 1, j − 1, a ]、[ i − 1, j , b ] 和[ i − 1, j + 1, c ] 灯点亮时打开时,[ i , j , s ]。我们通过将级别i − 1 的三个灯连接到与门来实现此目的,该与门的输出连接到[ i , j , s ] 灯。

Suppose that if cell [ i − 1, j − 1], cell [ i − 1, j ], and cell [ i − 1, j + 1] contain values ​​a , b , and c , respectively, then according to the transition function δ cell [ i , j ] contains s . We will wire the circuit so that when lamps light [ i − 1, j − 1, a ], light [ i − 1, j , b ], and light [ i − 1, j + 1, c ] light up, lamp light [ i , j , s ] also lights up . We achieve this by connecting the three lamps at level i − 1 to an AND gate whose output is connected to lamp light [ i , j , s ].

一般来说,可以有几种不同的设置 ( a 1 , b 1 , c 1 ), ( a 2 , b 2 , c 2 ), …, ( a l , b l , c l ) cells cell [ i − 1 , j − 1]、单元格[ i − 1, j ] 和单元格[ i − 1, j + 1],这可以导致单元格[ i , j ]包含s。在这种情况下,我们构建电路的方式是,对于每个设置a ib ic相应的灯都连接到与门,所有这些与门都连接到或门。这样的电路如下图所示。

In general, there can be several different arrangements ( a 1 , b 1 , c 1 ), ( a 2 , b 2 , c 2 ), …, ( a l , b l , c l ) of cells cell [ i − 1, j − 1], cell [ i − 1, j ] and cell [ i − 1, j + 1] that can cause cell [ i , j ] to contain s . In such a case, we construct the circuit in such a way that for each of these arrangements a i , b i , c i the corresponding lamps are connected to an AND gate, and all these AND gates are connected to an OR gate. Such a circuit is shown in the figure below.

9.32

一盏灯的电路

Figure 9.32

Circuit for one lamp

对每个灯重复所描述的电路,边缘处有一些例外。表格左侧边缘的每个单元格 -即 1 ≤ it ( n ) 的单元格[ i , 1]仅有两个影响其内容的前面单元格。类似的情况也适用于右岸的细胞。在这种情况下,我们修改电路来模拟图灵机M在这种情况下的行为。

The described circuit is repeated for each lamp with a few exceptions at the edges. Each cell on the left edge of the tableau – that is, cell [ i , 1] for 1 ≤ it ( n ) has only two preceding cells that affect its contents. An analogous situation applies to the cells on the right edge. In such cases, we modify the circuit to simulate the behavior of the Turing machine M in this situation.

第一行中的单元格没有前驱单元格,必须以特殊方式处理。这些单元包含初始配置,它们的灯连接到输入变量。灯[1, 1, q01 ] 连接到输入w 1 ,因为初始配置从初始状态符号q 0开始并且头部位于w 1上方。类似地,[1, 1, q00 ]通过非门连接到输入w 1 。灯[ 1, 2, 1], ..., light [1, n , 1] 仍然连接到输入w 2 , ..., w n,并且灯[1, 2, 0], ..., light [ 1, n , 0] 通过 NOT 门连接到这些输入,因为这些值是由输入字w确定的。此外,[1, n + 1, ], …,[1, t ( n ), ] 灯亮起,因为第一行中的剩余单元对应于磁带上最初为空的位置 ( )。最后,第一排剩余的所有灯都关闭。

The cells in the first row have no predecessors and must be handled in a special way. These cells contain the initial configuration, and their lights are connected to the input variables. The light [ 1, 1, q01 ] light is connected to the input w 1 , because the initial configuration starts with the initial state symbol q 0 , and the head is above w 1 . Similarly, the light [1, 1, q00 ] light is connected to the input w 1 by a NOT gate. In the following, the light [1, 2, 1], …, light [1, n , 1] lights are connected to the inputs w 2 , …, w n , and the light [1, 2, 0], …, light [1, n , 0] lights are connected to these inputs by NOT gates, because these values ​​are determined by the input word w . Additionally, the lights light [1, n + 1, ], …, light [1, t ( n ), ] are turned on, because the remaining cells of the first row correspond to positions on the tape that are initially empty ( ). Finally, all the remaining lights in the first row are turned off.

我们构建了一个电路,通过t ( n ) 个步骤来模拟机器M的操作。剩下要做的就是将其中一个门指定为电路的输出门。我们知道,如果机器 M 在步骤t ( n )的磁带左端包含⊔ 的单元格中处于q接受状态,则机器M接受单词w 。因此,我们将输出门指定为连接到灯的输出门[ t ( n ), 1, qaccept ]。至此定理的证明结束。

We have constructed a circuit that simulates the operation of the machine M for its t ( n ) steps. All that remains to be done is to designate one of the gates as the output gate of the circuit. We know that the machine M accepts a word w if it finds itself in the state q accept in the cell containing at the left end of the tape at step t ( n ). We therefore designate the output gate as the one connected to the light light [ t ( n ), 1, qaccept ]. This completes the proof of the theorem.

除了将电路复杂性与时间复杂性联系起来之外,定理 9.30 还提供了定理 7.27 的替代证明,即库克-莱文定理。如果输入变量值的某些设置导致电路返回值1,我们就说逻辑电路是可满足的。电路可满足性问题是检查电路是否可满足。让

In addition to relating circuit complexity to time complexity, Theorem 9.30 provides an alternative proof of Theorem 7.27, the Cook–Levin theorem. We say that a logical circuit is satisfiable if some setting of the input variables causes the circuit to return the value 1. The circuit satisfiability problem is to check whether the circuit is satisfiable. Let

CIRCUIT-SAT = { <C> C是可满足逻辑电路}

CIRCUIT-SAT = { C : C is a satisfiable logical circuit}.

定理9.30表明逻辑电路能够模拟图灵机。我们将使用这个结果来证明CIRCUIT-SAT问题是 NP 完备问题。

Theorem 9.30 shows that logical circuits are capable of simulating Turing machines. We will use this result to show that the CIRCUIT-SAT problem is NP-complete.

定理9.33

Theorem 9.33

CIRCUIT-SAT问题是 NP 完备问题。

The CIRCUIT-SAT problem is NP-complete.

证明 为了证明这个定理,我们需要证明 CIRCUIT-SAT 问题属于 NP 类,并且任何属于 NP 的语言A都可以简化为CIRCUIT-SAT问题。第一个性质是显而易见的。为了证明第二个,我们需要提出一个多项式约简f,将单词映射到电路,使得 z

Proof To prove this theorem, we need to show that the CIRCUIT-SAT problem belongs to NP and any language A belonging to NP is reducible to the CIRCUIT-SAT problem . The first property is obvious. To prove the second, we need to present a polynomial reduction f that maps words to circuits, such that

f ( w ) = 〈C〉

f ( w ) = C

它遵循

it turns out that

w A 逻辑电路C可满足。

w A logical circuit C is satisfiable.

由于语言A属于 NP 类,因此存在一个多项式时间验证机V ,其输入词的形式为x , c 其中c是表明x属于A 的证书。为了构造f ,我们使用定理 9.30 证明中提出的方法构建了一个电路模拟机V 。我们用单词w的符号填充与单词x的符号相对应的电路的输入变量。电路中唯一剩下的输入变量对应于证书c。以这种方式创建的电路称为C。

Since the language A is in NP, there exists a polynomial-time verifying machine V whose input word has the form x , c , where c is a certificate indicating that x is in A . To construct f , we construct a circuit simulating the machine V , using the method given in the proof of Theorem 9.30. The input variables of the circuit corresponding to the symbols of the word x are filled with the symbols of the word w . The only remaining input variables of the circuit correspond to the certificate c . We call the circuit thus constructed C .

如果电路C可满足,则可以证明单词w属于语言A。相反,如果w属于语言A,则有证明它的证书,因此电路C是可满足的。

If circuit C is satisfiable, then there is a certificate attesting that word w is a member of language A . Conversely, if w is a member of language A , then there is a certificate attesting to this, and therefore circuit C is satisfiable.

为了证明这种简化是在多项式时间内进行的,我们可以注意到定理 9.30 证明中所示的电路结构可以在关于n的多项式时间内实现。对于某些k ,验证机的运行时间为n k,因此构造的电路的大小为O ( n 2 k ) 。该电路的结构非常简单(包含许多重复元件),因此整个约简的运行时间为O ( n 2 k )。

To show that this reduction works in polynomial time, we can note that the circuit construction shown in the proof of Theorem 9.30 can be realized in polynomial time in n . The running time of the verifying machine is n k for some k , so the size of the constructed circuit is O ( n 2 k ). The circuit structure is quite simple (it contains many repeated elements), so the running time of the entire reduction is O ( n 2 k ).

现在我们可以证明3SAT问题是 NP 完备的,从而完成了库克-莱文定理的替代证明。

We can now show that the 3SAT problem is NP-complete, thus completing the alternative proof of the Cook–Levin theorem.

定理9.34

Theorem 9.34

3SAT问题是 NP 完备问题。

The 3SAT problem is NP-complete.

证明的概念3SAT 问题显然属于 NP 类。我们将证明 NP 类中的任何语言都可以在多项式时间内简化为3SAT 。我们将通过在多项式时间内将CIRCUIT-SAT问题简化为3SAT来实现这一点约简将电路C变换为公式Φ,因此当且仅当公式Φ可满足时, C才可满足。该公式将为每个变量和电路的每个门包含一个变量。

Concept of Proof The 3SAT problemis of course in NP. We will show that any language in NP can be reduced to 3SAT in polynomial time. We do this by reducing the CIRCUIT-SAT problem to 3SAT in polynomial time. The reduction transforms the circuit C into a formula Φ , such that C is satisfiable if and only if the formula Φ is satisfiable. The formula will contain one variable for each variable and each gate of the circuit.

从概念上讲,该公式模拟了电路。满足公式Φ的评估包括满足电路C的评估。它还包含C电路的每个门的值,用于C执行的计算以获得令人满意的评估。结果,满足Φ公式的评估“猜测”电路C的整个计算以满足电路的评估,并且Φ公式中的子句检查这些计算的正确性。此外,Φ包含一个子句,用于检查电路C的输出是否等于 1。

Conceptually, this formula simulates a circuit. The formula-satisfying evaluation Φ contains the satisfying evaluation of circuit C . It also contains the values ​​of each gate of circuit C for the computations performed by C for the satisfying evaluation. In effect, the formula-satisfying evaluation Φ “guesses” the entire computation of circuit C for the circuit-satisfying evaluation, and the clauses in the formula Φ check the correctness of these computations. Additionally, Φ contains a clause that checks whether the output of circuit C is equal to 1.

证明我们提出了f从CIRCUIT-SAT 问题3SAT问题 多项式时间约简。令C为具有输入x 1 , …, x l和门g 1 , …, g m的电路。基于C构建了一个公式Φ,其中包含变量x 1 , …, x l , g 1 , …, g m。公式Φ的每个变量对应于电路C中的一根导线。变量x对应于门的输入线,变量g对应于门的输出线。让我们将公式Φ的变量重命名为w 1 , …, w l + m

Proof We present a polynomial-time reduction f from the CIRCUIT-SAT problem to 3SAT . Let C be a circuit with inputs x 1 , …, x l and gates g 1 , …, g m . The reduction constructs from C a formula Φ containing variables x 1 , …, x l , g 1 , …, g m . Each variable of the formula Φ corresponds to a wire in circuit C . The variables x i correspond to the input wires, and the variables g i correspond to the output wires of the gates. Let us rename the variables of the formula Φ as w 1 , …, w l + m .

现在我们将描述公式Φ的子句。我们将使用含义更直观地编写它们。回想一下,蕴涵运算 ( P Q ) 可以写成 ( P Q )。电路C中的每个非门(输入线位于i且输出线位于j)等价于表达式

We now describe the clauses of the formula Φ . We will write them more intuitively using implications. Recall that the implication operation ( P Q ) can be written as ( P Q ). Each NOT gate in circuit C with input wire at i and output wire at j is equivalent to the expression

( w i w j ) ( w i w j ),

( w i w j ) ( w i w j ),

可以转化为两个子句

which can be transformed into two clauses

( w i w j ) ( w i w j )。

( w i w j ) ( w i w j ).

请注意,当且仅当ij中的变量被替换为与 NOT 门的正确操作相对应的值时,这两个子句才为 true。

Note that both clauses are true if and only if the variables w i and w j are substituted with values ​​that correspond to the correct operation of the NOT gate.

电路C中输入ij、输出k 的每个与门等价于表达式

Each AND gate in circuit C with inputs w i and w j and output w k is equivalent to the expression

又可以转化为四个子句

which in turn can be transformed into four clauses

类似地,电路C中的每个“或”门(输入位于ij且输出位于k)等价于表达式

Similarly, each OR gate in circuit C with inputs at i and at j and output at k is equivalent to the expression

我们将其转换为四个子句

which we will transform into four clauses

在每种情况下,当变量w iw jw k的值分配对应于门的正确功能时,所有四个子句都得到满足。另外,我们在Φ公式中添加一个子句(w m) ,其中w m对应于电路C的输出门。

In each case, all four clauses are satisfied if the assignment of values ​​to variables w i , w j , and w k corresponds to the proper functioning of the gate. Additionally, we include the clause ( w m ) in the formula Φ , where w m corresponds to the output gate of circuit C .

所描述的某些子句包含少于三个文字。我们可以通过重复文字将这些子句扩展到所需的大小。例如,我们将子句 ( w m ) 扩展为等效子句 ( w m w m w m )。这样就完成了公式Φ的构造。

Some of the clauses described contain fewer than three literals. We can expand these clauses to the desired size by repeating the literals. For example, we expand the clause ( w m ) to the equivalent clause ( w m w m w m ). This completes the construction of the formula Φ .

我们将简要地证明这种构造是正确的。如果存在满足电路C的输入变量的评估,那么我们通过分配变量g以及电路C对这些输入值的计算得到的值来获得满足Φ公式的评估。相反,如果存在满足公式Φ的评估,则它直接给出满足电路C 的评估,因为它描述了给出输出值 1 的电路C的所有计算。可以在多项式时间内执行归约,因为它很容易计算,并且生成的结果公式的大小相对于输入数据的大小是多项式的(基本上是线性的)。

We will briefly show that this construction works correctly. If there is a satisfying valuation of the input variables for circuit C , then we obtain a satisfying valuation of the formulas Φ by assigning to the variables g and the values ​​resulting from the computation of circuit C for these input values. Conversely, if there is a satisfying valuation of the formulas Φ , then this gives an explicit satisfying valuation for circuit C , since it describes the entire computation of circuit C that yields the output value 1. The reduction can be done in polynomial time, since it is easy to compute, and the size of the generated output formula is polynomial (in fact, linear) in the size of the input data.

练习

Exercises

A 9.1 证明TIME(2 n ) = TIME(2 n +1 )。

A 9.1 Prove that TIME(2 n ) = TIME(2 n +1 ).

A 9.2 证明TIME(2 n ) TIME(2 2 n )。

A 9.2 Prove that TIME(2 n ) TIME(2 2 n ).

A 9.3 证明NTIME( n ) ⊊PSPACE

A 9.3 Prove that NTIME( n ) PSPACE.

9.4 通过显示所有门计算的值来显示图 9.26 中的电路对输入 0110 的计算结果,如图 9.24 所示。

9.4 Show what the circuit in Figure 9.26 calculates for input 0110, showing the values ​​calculated by each gate as in Figure 9.24.

9.5 给出一个计算三个输入变量的奇偶校验函数的电路示例,并说明它如何适用于输入 011。

9.5 Give an example of a circuit that calculates a parity function for three input variables and show how it works for input 011.

9.6 证明如果A P,则P A = P。

9.6 Prove that if A P, then P A = P.

9.7 列出下列语言在字母表{0,1}上生成的求幂正则表达式:

9.7 Give regular expressions with exponentiation that generate the following languages ​​over the alphabet {0,1}:

A a. 长度为 500 的所有单词。

A a. All words of length 500.

A b. 长度不超过 500 字的所有单词。

A b. All words of length 500 or less.

A c. 所有长度为 500 或以上的单词。

A c. All words of length 500 or more.

A d. 长度不为 500 的所有单词。

A d. All words of length other than 500.

e. 恰好包含 500 个的单词。

e. All words containing exactly 500 ones.

f. 所有包含至少 500 个 1 的单词。

f. All words containing at least 500 ones.

g. 最多包含 500 个的所有单词。

g. All words containing at most 500 ones.

h. 长度为 500 或以上且第 500 个位置包含 0 的所有单词。

h. All words of length 500 or greater that contain a 0 in the 500th position.

i. 所有包含两个零且其间至少有 500 个符号的单词。

i. All words containing two zeros with at least 500 symbols between them.

9.8 如果R是正则表达式,则令R { m , n }表示一个表达式

9.8 If R is a regular expression, let R { m , n } denote the expression

R m R m +1 R n

R m R m +1 R n .

展示如何使用正则求幂运算符,但不使用“ ... ”来实现R运算符{ m , n } 。

Show how to implement the R { m , n } operator using the regular exponentiation operator, but without the " ... ".

9.9 证明如果 NP = P SAT,则 NP = coNP。

9.9 Prove that if NP = P SAT , then NP = coNP.

9.10 在问题 8.13 中,我们证明 A LBA语言是 PSPACE 完备的。

9.10 In Problem 8.13 we showed that the language A LBA is PSPACE-complete.

a. 我们可以得出 A LBA NL 的结论吗?证明你的答案合理。

a. Can we state that A LBA NL? Justify your answer.

b. 我们可以得出 A LBA P 的结论吗?证明你的答案是正确的。

b. Can we state that A LBA P? Justify your answer.

9.11 证明问题7.48中描述的MAX-CLIQUE语言属于P SAT

9.11 Prove that the language MAX-CLIQUE described in Exercise 7.48 belongs to P SAT .

任务

Tasks

9.12解释以下 P NP 的错误“证明”中的错误所在。让我们假设P = NP,这将导致矛盾。如果 P = NP,则SAT Î P,因此对于某些k,我们有SAT Î TIME( n k )。由于 NP 类中的每种语言均可通过多项式时间简化为SAT问题,因此 NP TIME( n k )成立。结果是 P TIME( n k )。然而,时间层次定理意味着 TIME( n k +1 ) 包含不属于 TIME( n k ) 的语言,这与 P ⊆ TIME( n k )的假设不一致。因此 P NP。

9.12 Explain the flaw in the following false "proof" that P NP. Assume that P = NP and we reach a contradiction. If P = NP, then SAT P, so for some k we have SAT TIME( n k ). Since every language in NP is reducible in polynomial time to SAT , NP TIME( n k ). Hence P TIME( n k ). However, the time hierarchy theorem implies that TIME( n k +1 ) contains a language that is not a member of TIME( n k ), which contradicts the assumption that P TIME( n k ). Hence P NP.

9.13 考虑功能Σ * × N Σ *#* 定义如下。设pad ( s , l ) = s # j,其中j = max(0, lm ),m是s的长度。因此pad ( s , l ) 只是将新 # 符号的足够副本添加到单词s的末尾,以便生成的单词至少有l长。对于任何语言A和函数f : N N,我们将语言pad ( A , f ) 定义为

9.13 Consider the function pad : Σ * × N Σ *#* defined as follows. Let pad ( s , l ) = s # j , where j = max(0, lm ), and m is the length of s . Then pad ( s , l ) simply adds enough copies of the new symbol # to the end of the word s so that the length of the resulting word is at least l . For any language A and function f : N N we define the language pad ( A , f ) as

pad ( A , f ) = { pad ( s , f ( m )) :其中s Am是s的字长}。

pad ( A , f ) = { pad ( s , f ( m )) : where s A , and m is the length of word s }.

证明如果 A Î TIME( n 6 ),则pad ( A , n 2 ) Î TIME( n 3 )。

Prove that if A TIME( n 6 ), then pad ( A , n 2 ) TIME( n 3 ).

9.14 证明如果 NEXPTIME EXPTIME,则 P NP。问题 9.13 中定义的pad函数可能有用。

9.14 Prove that if NEXPTIME EXPTIME, then P ≠ NP. The function pad defined in Problem 9.13 may be useful .

A 9.15让我们像问题 9.13 一样定义pad 函数

A 9.15 Let us define the pad functionas in Task 9.13.

a. 证明对于每种语言A和自然数k,当且仅当pad ( A , n k ) P 时,我们有A P。

a. Prove that for every language A and natural number k we have A P if and only if pad ( A , n k ) P.

b. 证明 P SPACE( n )。

b. Prove that P SPACE( n ).

9.16 证明TQBF \SPACE( n 1/3 )。

9.16 Prove that TQBF \ SPACE( n 1/3 ).

*9.17 回想一下问题 5.26 中提出的 2DFA(双头有限状态机)的定义。证明 P 包含 2DFA 无法识别的语言。

*9.17 Recall the definition of a 2DFA (two-head finite state machine) given in Problem 5.26. Prove that P contains a language that is not recognizable by a 2DFA.

9.18 令 E REX = { R R是求幂正则表达式,且 L( R ) = Ø }。证明E REX P。

9.18 Let E REX = { R : R is a regular expression with exponentiation and L( R ) = Ø }. Prove that E REX P.

9.19让我们将唯一卫星 问题定义为

9.19 Let us define the unique-sat problem as

USAT = { 〈Φ〉 : Φ是一个可以由一个变量求值满足的逻辑公式}。

USAT = { 〈Φ〉 : Φ is a logical formula that is satisfied by exactly one valuation of the variables}.

证明USAT P SAT

Prove that USAT P SAT .

9.20 证明存在一个预言机C,其中NP C coNP C

9.20 Prove that there exists an oracle C such that NP C coNP C .

9.21 向预言机提出 k 个问题图灵机是指具有对每个输入单词最多执行k次查询的预言机。我们将编写一台机器M,向预言机提出语言A 的k 个问题,即M A, k。让我们将 P A, k定义为图灵机可在多项式时间内判定的语言集合,其中k 个预言机查询语言A

9.21 A Turing machine with k queries to the oracle is a machine with an oracle that can execute at most k queries for each input word. A machine M with k queries to the oracle for language A will be written as M A, k . Let us define P A, k to be the set of languages ​​decidable in polynomial time by Turing machines with k queries to the oracle for language A .

a. 证明 NP coNP P SAT,1

a. Show that NP coNP P SAT,1 .

b. 假设 NP coNP。证明然后 NP coNP P SAT,1

b. Assume that NP coNP. Show that then NP coNP P SAT,1 .

9.22 假设A和 B是两个预言机。一个是TQBF语言的预言机,但我们不知道是哪一个。提供一种可以访问两个预言机并能在多项式时间内解析TQBF语言的算法。

9.22 Suppose A and  B are two oracles. One is an oracle for the TQBF language , but we do not know which one. Give an algorithm that has access to both oracles and that resolves the TQBF language in polynomial time.

9.23 回想一下,我们可以考虑通过指定多个输出门来返回字母表 {0,1} 上的单词的电路。令add n : {0,1} 2 n {0,1} n +1为一个电路,该电路采用两个n位整数作为输入并计算它们的n +1 位和。证明函数add n可以使用大小为O ( n )的电路来计算。

9.23 Recall that we can consider circuits that return words over the alphabet {0,1} by designating many output gates. Let add n : {0,1} 2 n {0,1} n +1 be a circuit that takes two n -bit integers as input and computes their n +1-bit sum. Show that the function add n can be computed using circuits of size O ( n ).

9.24 让我们将函数多数n : {0,1} n {0,1} 定义为

9.24 Let us define the majority function n : {0,1} n {0,1} as

换句话说,多数n返回输入数据中更频繁出现的值。证明多数函数n可以使用以下公式计算:

In other words, the majority n function returns the value that occurs most frequently among the inputs. Show that the majority n function can be computed using:

a.尺寸为O ( n 2 ) 的周长。

a. A circumference of size O ( n 2 ).

b.大小为O ( n log n ) 的电路。 (提示:递归地将输入变量的数量减半并使用问题 9.23 的结果。)

b. A circuit of size O ( n log n ). (Hint: Recursively divide the number of input variables in half and use the result of Problem 9.23.)

*9.25让我们像问题 9.24 一样定义多数n 函数。证明它可以使用大小为O ( n )的电路来计算。

*9.25 Let us define the majority function n as in Problem 9.24. Show that it can be computed using a circuit of size O ( n ).

精选解决方案

Selected solutions

9.1 时间复杂度类是使用大O表示法定义的,因此常数系数没有意义。函数 2 n +1的复杂度为O (2 n ),因此A Î TIME(2 n ) 当且仅当A Î TIME(2 n +1 )。

9.1 The time complexity classes are defined using big O notation , so constant coefficients do not matter. A function 2 n + 1 is O (2 n ), so A TIME(2 n ) if and only if A TIME(2 n + 1 ).

9.2 包含 TIME(2 n ) TIME(2 2 n ) 成立,因为 2 n ≤ 2 2 n。根据时间层次定理,这种遏制是正确的。函数 2 2 n是时间可构造的,因为图灵机可以在时间O (2 2 n ) 内存储数字 1 后跟 2 n个零。层次定理保证存在一种语言A可以在时间O (2 2 n ) 内解析,但不能在时间o (2 2 n / log 2 2 n ) = o (2 2 n /2 n ) 内解析。因此,A TIME(2 2 n ),但A TIME(2 n )。

9.2 The inclusion TIME(2 n ) TIME(2 2 n ) holds, since 2 n ≤ 2 2 n . This inclusion is proper by the time hierarchy theorem. The function 2 2 n is constructible in time, since a Turing machine can store the number 1 followed by 2n zeros in time O (2 2 n ). The hierarchy theorem guarantees that there exists a language A that is decidable in time O (2 2 n ), but not in time o (2 2 n / log 2 2 n ) = o (2 2 n /2 n ). Thus A TIME(2 2 n ), but A TIME(2 n ).

9.3 NTIME( n ) NSPACE( n ),因为在每个计算路径上在时间t ( n )运行的任何图灵机最多可以使用t ( n ) 个磁带单元。此外,根据萨维奇定理,NSPACE( n ) SPACE(n 2 ) 。然而,根据记忆层次定理,我们有 SPACE( n 2 ) SPACE( n 3 )。通过 SPACE( n 3 ) PSPACE得到最终结果。

9.3 NTIME( n ) NSPACE( n ), since any Turing machine operating in time t ( n ) on each path of computation can use at most t ( n ) tape cells. Moreover, NSPACE( n ) SPACE(n 2 ) by Savitch's theorem. However, by the memory hierarchy theorem, we have SPACE( n 2 ) SPACE( n 3 ). The final result is obtained by containing SPACE( n 3 ) PSPACE.

9.7Σ500 ( b ) ( Σ ε ) 500 ; ( c ) Σ 500 Σ *; ( d ) ( Σ ε ) 499 Σ 501 Σ *。

9.7 ( a ) Σ 500 ; ( b ) ( Σ ε) 500 ; ( c ) Σ 500 Σ *; ( d ) ( Σ ε) 499 Σ 501 Σ *.

9.15 (a)A为任意语言且k N。如果A P,则pad ( A , n kΠ P,因为我们可以通过将w写成s # l确定是否w pad ( A , n k ) ,其中单词s不包含符号 #。然后我们检查是否 |w| = | s | k,最后,是否Π A。在多项式时间内实现第一个测试很简单。第二个测试在Poly (| s |) 时间内运行,并且因为 | s | ≤ | w |,它以多项式时间(| w |)运行,即以多项式时间运行。如果pad ( A , n k ) P,则A P,因为我们可以通过将一个单词与 # 符号对齐直到达到长度 |来确定它是否在 Î  A中。| k,然后检查结果是否属于pad ( A , n k )。两种操作都只需要多项式时间。

9.15 (a) Let A be any language and k N . If A P, then pad ( A , n kΠ P, since we can determine whether w pad ( A , n k ) by writing w as s # l , where the word s does not contain the symbol #. We then check whether |w| = | s | k , and finally whether Π A . The polynomial-time implementation of the first test is straightforward. The second test runs in poly (| s |), and since | s | ≤ | w |, it runs in poly (| w |), which is polynomial time. If pad ( A , n k ) P, then A P, since we can determine whether a word Π A by lining it up with # symbols until it reaches length | w | k , and then checking if the result is pad ( A , n k ). Both operations require only polynomial time.

( b ) 假设 P = SPACE( n )。设A是属于类SPACE( n 2 )的语言,但不属于类SPACE( n ),其存在性由层次定理得出。 Language pad ( A , n 2 ) SPACE( n ),因为我们有足够的内存来执行语言A的O ( n 2 )内存算法,使用语言pad函数扩展的语言的线性内存。通过假设,我们有pad ( A , n 2 ) P,因此基于点 (a) A ∈ P,即A SPACE( n ),同样基于假设。然而,这是一个矛盾。

( b ) Assume that P = SPACE( n ). Let A be a language of class SPACE( n 2 ) but not of class SPACE( n ), the existence of which follows from the hierarchy theorem. The language pad ( A , n 2 ) SPACE( n ), since we have enough memory to execute an algorithm that runs in O ( n 2 ) memory for language A , using linear memory for the language extended by the language function pad . By assumption, we have pad ( A , n 2 ) P, and so A P by (a), so A SPACE( n ), again by assumption. But this is a contradiction.



复杂性理论的10 个高级主题

10

Advanced Topics in Complexity Theory

在本章中,我们将简要介绍复杂性理论的一些附加主题。该理论是一个深入研究的领域,并且有大量关于该主题的文献。本章包含一些更高级的主题,但不能被视为对该主题的详尽回顾。特别是,超出本书范围的两个重要主题此处不予讨论:量子计算和概率可验证证明。对复杂性理论先前工作的回顾可以在《理论计算机科学手册》 [77]中找到。

In this chapter, we will briefly introduce some additional topics in complexity theory. This theory is an area of ​​intensive research, and there is a large literature on it. This chapter includes a selection of more advanced topics, but it cannot be considered an exhaustive review of the subject. In particular, two important topics that are beyond the scope of this book are not discussed here: quantum computation and probabilistically verifiable proofs. A review of earlier work in complexity theory can be found in the Handbook of Theoretical Computer Science [77].

在本章中,我们包括了关于近似算法、概率算法、交互式证明系统、并行计算和密码学的小节。除了概率算法之外,这些部分彼此独立,概率算法用于交互式证明系统和密码学的小节中。

In this chapter, we have included sections on approximation algorithms, probabilistic algorithms, interactive proof systems, parallel computing, and cryptography. These sections are independent of each other, except for probabilistic algorithms, which are used in the sections on interactive proof systems and cryptography.

10.1

近似算法

10.1

Approximation algorithms

在称为优化问题的一类问题中,我们在一组可能的解决方案中寻找最佳解决方案。例如,我们可能想要找到图中最大的团、最小的顶点覆盖率或连接两个顶点的最短路径。当优化问题是 NP 难题时(如前两个示例),除非 P = NP,否则没有多项式时间算法可以找到最佳解决方案。

In the category of problems called optimization problems, we seek the best solution in a set of possible solutions. For example, we might want to find the largest clique in a graph, the smallest vertex cover, or the shortest path connecting two vertices. When the optimization problem is NP-hard, as in the first two examples, there is no polynomial-time algorithm for finding the best solution unless P = NP.

在实践中,我们不一定需要问题的最佳(最优)解决方案。足够好的可能是更容易找到的接近最优的解决方案。顾名思义,近似算法旨在找到这种近似最优解。

In practice, we don't necessarily need the best ( optimal ) solution to the problem. A nearly optimal solution, much easier to find, may be good enough. As the name suggests, an approximation algorithm is designed to find such approximately optimal solutions.

例如,考虑我们在 7.5 节中介绍的顶点覆盖问题。我们将其作为代表决策问题的VERTEX-COVER语言呈现- 即答案为“是”或“否”的问题。在这个问题的优化版本中,我们将其称为MIN-VERTEX-COVER,我们将努力构造给定图的所有可能覆盖中最小的顶点覆盖之一。以下多项式时间算法找到该问题的近似解。它创建的顶部覆盖范围最多是最小覆盖范围的两倍。

For example, consider the vertex-cover problem that we introduced in Section 7.5. There we presented it as a VERTEX-COVER language representing a decision problem —one for which the answer is either yes or no. In the optimization version of this problem, which we will call MIN-VERTEX-COVER , we aim to construct one of the smallest vertex covers among all possible vertex covers of a given graph. The following polynomial-time algorithm finds an approximate solution to this problem. It constructs a vertex cover that is at most twice as large as the smallest cover.

A = "对于输入词G ,其中G是无向图:

A = "For input G , where G is an undirected graph:

  1. 重复以下操作,直到图形G的所有边都接触 ( touch ) 标记的边:
  2. Repeat the following until all edges of G touch the labeled edges:
  3. 在图G中找到一条不接触任何标记边的边。
  4. Find an edge in the graph G that does not touch any labeled edge.
  5. 标记这个边缘。
  6. Label this edge.
  7. “返回选定边的所有端点。”
  8. Return all vertices that are endpoints of selected edges."

定理10.1

Theorem 10.1

算法A在多项式时间内运行并生成不大于最小可能顶点覆盖大小两倍的顶点覆盖。

Algorithm A runs in polynomial time and produces a vertex cover that is no larger than twice the size of the smallest possible vertex cover.

证明 算法A显然是在多项式时间内运行的。令X为其返回的顶点集,H 为选定边的集。我们知道X是顶点覆盖,因为 H 包含或触及G的每条边,因此X触及G

Proof Algorithm A obviously runs in polynomial time. Let X be the set of vertices it returns, and H be the set of selected edges. We know that X is a vertex cover since H contains or touches every edge of G , and therefore X touches all edges of G .

为了证明集合X至多是最小顶点覆盖Y大小的两倍我们可以注意到两个事实:第一个是 H 中的每条边向X引入两个顶点,因此X 的元素数量是 H 的两倍。至于第二个事实,我们知道Y是顶点覆盖,因此 H 中的每条边至少有一个顶点.没有这样的顶点接触 H 中的两条边,因为属于 H 的边不互相接触。因此, Y 的顶点覆盖至少与 H 一样大,因为Y包含接触 H 中每条边的不同顶点。因此,集合X不能比集合Y大两倍以上。

To show that the set X is at most twice as large as the smallest vertex cover Y , we can note two facts: X is twice as large (has twice as many elements) as the set H , and H is not larger than Y . The first follows from the fact that each edge of H introduces two vertices into X , so X has twice as many elements as H. As for the second fact, we know that Y is a vertex cover, so each edge of H has at least one vertex in Y . No such vertex touches two edges in H , since edges in H do not touch each other. Hence, the vertex cover of Y is at least as large as H , since Y contains distinct vertices that touch every edge in H. Therefore, the set X cannot be more than twice as large as Y .

MIN-VERTEX-COVER是最小化问题的一个示例,因为我们正在寻找一组可能的解决方案中最小的一个。在最大化问题中,我们努力寻找最大的解决方案。如果最小化问题的近似算法总是找到比最优解大不超过k倍的解,则该算法称为k 最优算法。前面显示的算法对于顶点覆盖问题来说是 2 最优的。在k最优最大化问题的情况下,近似算法总是找到大小至少为最优解大小的1/ k的解。

MIN-VERTEX-COVER is an example of a minimization problem , since we are looking for the smallest possible solution. In a maximization problem , we are trying to find the largest solution. An approximation algorithm for a minimization problem is called k-optimal if it always finds a solution that is no more than k times larger than the optimal one. The algorithm shown earlier is 2-optimal for the vertex cover problem. In the case of a maximization problem, a k -optimal approximation algorithm always finds a solution whose size is at least 1/ k the size of the optimal solution.

我们现在提出一个MAX-CUT最大化问题的近似算法。无向图中的是将顶点集V划分为两个不相交的子集 S 和 T。割边是连接 S 中的某个顶点与 T 中的某个顶点的边。未割边是这样的边:不是尖端。切割尺寸是切割边缘的数量。MAX-CUT问题是寻找图G中的最大割。正如我们在问题 7.27 中所示,这个问题是 NP 完备问题。

We now present an approximation algorithm for the maximization problem MAX-CUT . A cut in an undirected graph is a partition of a set of vertices V into two disjoint subsets S and T. A cut edge is an edge connecting some vertex in S to some vertex in T. A noncut edge is an edge that is not an edge of the cut. The size of a cut is the number of edges in the cut. The MAX-CUT problem consists in finding the largest cut in the graph G . As we showed in Problem 7.27, this problem is NP-complete.

以下算法以 2 倍近似求解 MAX-CUT 问题。

The following algorithm approximates the solution to the MAX-CUT problem with a factor of 2.

B = "对于输入词G ,其中G是具有顶点集V的无向图:

B = "For input G , where G is an undirected graph with vertex set V :

  1. 令 S = Ø且 T = V。
  2. Let S = Ø and T = V .
  3. 如果将单个顶点从 S 移动到 T 或从 T 移动到 S 会增加切割的大小,则进行此移动并重复此步骤。
  4. If moving a single vertex from S to T or from T to S increases the size of the cut, then make that move and repeat this step.
  5. 如果没有更多顶点移动会增加切割尺寸,则返回当前切割并退出。”
  6. If there are no more vertices that would increase the cut size by moving them, return the current cut and end."

该算法从(大概)错误的剪切开始,并执行局部校正,直到不可能进行局部校正。虽然此过程通常不会提供最佳切割,但我们可以证明它返回的结果至少是最佳切割大小的一半。

This algorithm starts with a (presumably) bad cut and performs local corrections until no local corrections are possible. Although this procedure will not generally produce an optimal cut, we can show that it produces a result that is at least half the size of an optimal cut.

定理10.2

Theorem 10.2

算法B是MAX-CUT问题的多项式时间 2 最优近似算法。

Algorithm B is a polynomial-time 2-optimal approximation algorithm for the MAX-CUT problem .

证明 算法B以多项式时间运行,因为每次执行步骤 2 都会增加切割的大小,并且该大小的最大值是图G中的边总数。

Proof Algorithm B runs in polynomial time since each execution of step 2 increases the cut size, and the maximum value of this size is the total number of edges in the graph G .

现在我们将证明算法B执行的切割至少是最佳切割大小的一半。事实上,我们将展示一个更强有力的事实:割B包含图G的所有边的至少一半。请注意,对于G 的每个顶点,接触它的切割边的数量至少与未切割边的数量一样大,否则算法B会将该顶点移动到另一侧。我们将所有顶点的切割边数相加。该总和是切削刃总数的两倍,因为每个切削刃将被计数两次,每端一次。根据之前的观察,该总和必须至少等于每个顶点的相应未切割边的总和。因此,图G包含的切割边至少与未切割边一样多。因此,割线至少包含图所有边的一半。

We now show that the cut performed by algorithm B is at least half the size of an optimal cut. In fact, we will show a stronger fact: cut B contains at least half of all edges of graph G . Notice that for each vertex of graph G, the number of cut edges touching it is at least as large as the number of uncut edges, since otherwise algorithm B would move that vertex to the other side. We sum the numbers of cut edges for all vertices. This sum is twice the total number of cut edges, since each such edge will be counted twice, once for each endpoint. From the earlier observation, this sum must be at least equal to the corresponding sum of uncut edges for each vertex. Thus, graph G contains at least as many cut edges as uncut edges. The cut therefore contains at least half of all edges in the graph.

10.2

概率算法

10.2

Probabilistic algorithms

概率(随机)算法是使用特定随机过程的算法。通常,这种类型的算法包括诸如“抛硬币”之类的操作,并且这些抛硬币的结果影响算法的进一步操作及其结果。使用概率算法似乎比确定性算法更容易解决某些类型的问题。

A probabilistic (randomized) algorithm is an algorithm that uses a random process in its operation. Typically, an algorithm of this type involves operations such as "flipping a coin" and the results of these tosses affect the further operation of the algorithm and its outcome. Certain types of problems seem to be easier to solve using probabilistic algorithms than deterministic algorithms.

在给定情况下,通过抛硬币做出决策怎么会比实际计算甚至估计最佳选择更好呢?有时,计算最佳选择可能需要大量时间,并且其估计可能会出现错误,导致结果毫无用处。例如,统计学家使用随机抽样来确定大量人口中个体的信息,例如品味和政治偏好。对每个人进行调查会花费太长时间,而且向非随机选择的群体提问可能会导致错误的结论。

How could making decisions by flipping a coin be better than actually calculating or at least estimating the best choice in a given situation? Sometimes calculating the best choice can be extremely time-consuming, and estimating it can be subject to error that makes the result useless. For example, statisticians use random sampling to determine information about individuals in a large population, such as tastes or political preferences. Surveying everyone would take too long, and asking a nonrandomly selected group could lead to false conclusions.

BPP类

BPP Class

我们将通过定义概率图灵机的模型来开始对概率计算的正式讨论。然后,我们介绍与高效随机计算相关的复杂性类别和一些示例。

We begin our formal discussion of probabilistic computation by defining a model of a probabilistic Turing machine. We then present the complexity class related to efficient random computation and some examples.

定义10.3

Definition 10.3

概率图灵机 M是一种非确定性图灵机,其中每个非确定性步骤称为硬币翻转(随机步骤) - 这样的步骤有两个允许的下一步。输入单词的机器M的每个计算路径b 我们分配其出现的概率如下。我们将路径概率b定义为

A probabilistic Turing machine M is a type of nondeterministic Turing machine in which each nondeterministic step is called a coin toss (random step) – such a step has two allowed next moves. To each computation path b of M for input word w we assign a probability of its occurrence as follows. We define the probability of path b as

Pr[ b ] = 2 k

Pr[ b ] = 2 k ,

其中k是路径b上发生的硬币翻转次数。我们将机器M接受单词w的概率定义为

where k is the number of coin tosses occurring on path b . The probability that machine M accepts word w is defined as

Pr[ M接受w ] = Σ b接受Pr[ b ] 的路径。

Pr[ M accepts w ] = Σ b is a path accepting Pr[ b ].

换句话说,机器M接受单词w的事件的概率就是如果我们通过掷硬币来模拟机器M接受单词w来确定在每个随机步骤中采取什么动作,我们可以实现接受配置的概率。我们还将定义

In other words, the probability of the event that a machine M accepts a word w is the probability that we will be able to reach an accepting configuration if we simulate the machine M for a word w , tossing a coin to determine what move to make at each random step. We also define

Pr[ M拒绝w ] = 1 − Pr[ M接受w ]。

Pr[ M rejects w ] = 1 − Pr[ M accepts w ].

当概率图灵机解析一种语言时,它必须接受属于该语言的所有单词并拒绝该语言之外的所有单词,但现在我们允许机器以很小的概率犯错误。对于 0 ≤ ε < ½,我们会说机器 M以 错误概率 ε解析语言A ,当

When a probabilistic Turing machine decides a language, it must accept all words belonging to that language and reject all words not belonging to that language, except that now we allow the machine to make mistakes with a small probability. For 0 ≤ ε < ½ we will say that the machine M decides a language A with  error probability ε , when

  1. 如果w A,则 Pr[ M接受w ] ≥ 1 – ε。
  2. If w A , then Pr[ M accepts w ] ≥ 1 – ε.
  3. 如果w A,则 Pr[ M拒绝w ] ≥ 1 − ε 。
  4. If w A , then Pr[ M rejects w ] ≥ 1 − ε.

换句话说,通过模拟机器M的操作得到错误答案的概率至多为ε。我们还将根据输入单词n的长度考虑对错误概率的约束。例如,错误概率 ε = 2 n表示犯错误的概率呈指数小。

In other words, the probability of getting an incorrect answer by simulating the operation of machine M is at most ε. We will also consider bounds on the error probability that depend on the length of the input word n ​​. For example, the error probability ε = 2 n means an exponentially small probability of making an error.

我们对在时间和内存方面都高效的概率算法感兴趣。我们将以与非确定性图灵机相同的方式测量概率图灵机的时间和内存复杂度:对每个输入单词使用最坏情况的计算路径。

We are interested in probabilistic algorithms that are efficient in both time and memory. We will measure the time and memory complexity of a probabilistic Turing machine in the same way as for a nondeterministic Turing machine: by using the worst-case path of computation for each input word.

定义10.4

Definition 10.4

BPP是一类由在多项式时间内运行、错误概率为1/3的概率图灵机解析的语言。

BPP is a class of languages ​​that are decided by probabilistic Turing machines that run in polynomial time with an error probability of 1/3.

我们已经为错误概率B定义了此类,但只要错误概率落在后面提出的强化引理从 0 到 A 的开区间内,任何常数值都会给出等效定义。它提供了一种以指数方式降低错误概率的简单方法。请注意,对于错误概率为 2 −100的概率算法,由于运行该算法的计算机故障而获得错误答案的风险比由于不幸的硬币翻转而获得错误答案的风险要大得多。

We have defined this class for the error probability B , but any constant value would provide an equivalent definition, as long as the error probability is in the open interval 0 to A by the next reinforcement lemma . It provides a simple way to exponentially reduce the error probability. Note that for a probabilistic algorithm whose error probability is 2 −100 , the risk of getting an incorrect answer is much higher due to a failure of the computer running it than due to an unlucky coin toss.

引理10.5

Lemma 10.5

令 ε 为 0 到 1/2 开区间中的固定常数,则对于任意多项式p ( n ),在多项式时间内运行且误差概率为 ε 的概率图灵机M 1具有等效于在多项式时间内运行的概率图灵机M 2错误概率为 2 p ( n )

Let ε be a fixed constant in the open interval from 0 to ½, then for any polynomial p ( n ) a probabilistic Turing machine M 1 running in polynomial time with error probability ε has an equivalent probabilistic Turing machine M 2 running in polynomial time with error probability 2 p ( n ) .

证明的概念 机器M 2通过多次运行多项式并返回更频繁的答案来模拟M 1 。错误概率随着机器M 1启动的次数呈指数下降。

Proof Concept Machine M 2 simulates M 1 by running it polynomially many times and returning the answer that is obtained more often. The probability of error decreases exponentially with the number of times that machine M 1 is run .

考虑 ε = B时的情况。这对应于一个包含许多红色和蓝色球的盒子。我们知道这些球中的B是一种颜色,其余的B 是另一种颜色,但我们不知道哪种颜色占主导地位。我们可以通过反复(比如一百次)从盒子中抽出球来检查这一点,以确定哪种颜色出现的频率更高。盒子中的主色几乎肯定会在此示例中更常见。

Consider the case where ε = B . This corresponds to a box containing many red and blue balls. We know that B of these balls are of one color and the remaining B of another, but we do not know which color is dominant. We can test this by drawing balls from the box many times—say, a hundred times—to determine which color will appear more often. Almost certainly, the color dominant in the box will appear more often in this sample.

这些球对应于 M 1机器的计算路径:红色接受,蓝色拒绝。机器M 2对颜色进行采样,模拟机器M 1的操作。可以计算出,如果机器M 2以多项式多次运行机器M 1并返回出现次数最多的答案,那么机器M 2将以指数小概率出错。

The balls correspond to the computation paths of machine M 1 : red accepts, blue rejects. Machine M 2 samples a color, simulating the action of machine M 1 . It can be calculated that machine M 2 will be wrong with an exponentially small probability if it runs machine M 1 polynomially many times and returns the answer that occurs most often.

证明 给定图灵机M 1以错误概率 ε < ½ 解析语言和多项式p ( n ),我们将构造一个以概率 2 p ( n )解析相同语言的图灵机M 2

Proof Given a Turing machine M 1 that decides a language with error probability ε < ½ and a polynomial p ( n ), we can construct a Turing machine M 2 that decides the same language with probability 2p ( n ) .

M 2 =“对于输入词x

M 2 = "For input word x :

  1. 计算k的值(参见算法下面的分析)。
  2. Calculate the value of k (see analysis below the algorithm).
  3. 对输入字x执行M 1机器的2k 次独立模拟。
  4. Perform 2 k independent simulations of machine M 1 for input word x .
  5. 如果机器M 1的大多数运行结果都接受,则接受;否则丢弃。”
  6. If most of the runs of machine M 1 result in acceptance, accept ; otherwise reject ."

我们将估计机器M 2对输入单词x返回错误答案的概率1。在步骤2中,我们获得了M 1操作的2 k 个模拟结果序列,每个结果要么是正确的,要么是错误的。如果这些结果大部分都是正确的,那么机器M 2将返回正确的答案。我们将估计这些结果中至少一半是不正确的概率。

We estimate the probability 1 that the machine M 2 will return an incorrect answer for input word x . In Step 2, we obtain a sequence of 2 k results of simulations of the operation of M 1 , each of which is either correct or incorrect. If most of these results are correct, then the machine M 2 will return a correct answer. We estimate the probability that at least half of these results are incorrect.

令S 为机器M 2在步骤2 中可以获得的任何结果序列。令P S为机器M 2获得该结果的概率。假设S包含c个正确答案和错误答案因此w =​​ 2k。如果c≤w并且机器M 2接收到响应序列S,则机器M 2的响应将是错误的。我们将这样的响应序列 S 称为坏序列。让我们用 ε x表示机器M 1对单词x的响应不正确的概率。如果 S 是任意坏序列,则P S ≤ (ε x ) w (1 − ε x ) c,最多为 ε w (1 − ε) c,因为 ε x ≤ ε < ½,因此 ε x ( 1 − ε x ) ≤ ε(1 − ε),且由于cw。此外,ε w (1 − ε) c不大于 ε k (1 − ε) k,因为kw且 ε < 1 − ε。

Let S be any sequence of results that machine M 2 could have obtained in step 2. Let P S be the probability of machine M 2 obtaining this result . Assume that S contains c correct answers and w incorrect answers, so w = ​​2 k . If cw and machine M 2 received the sequence of answers S, then machine M 2 's answer will be incorrect. We will call such a sequence of answers S a bad sequence . Let us denote by ε x the probability that machine M 1 's answer for word x is incorrect. If S is an arbitrary bad sequence, then P S ≤ (ε x ) w (1 − ε x ) c , which is at most ε w (1 − ε) c , since ε x ≤ ε < ½, and therefore ε x (1 − ε x ) ≤ ε(1 − ε), and since cw . Moreover, ε w (1 − ε) c is not greater than ε k (1 − ε) k , since kw and ε < 1 − ε.

通过对所有坏序列 S 求和P S ,我们得到机器M 2返回错误答案的概率。最多有 2 2 k 个坏字符串,因为 2 2 k是所有字符串的数量。因此

Summing P S for all bad strings S gives the probability that the machine M 2 will return an incorrect answer. There are at most 2 2 k bad strings, since 2 2 k is the number of all strings. Hence

我们假设ε < 1/2,所以4ε(1 − ε) < 1。因此,上面计算的概率随着k的增加呈指数下降,机器M 2的错误概率也以同样的方式下降。为了计算k的特定值,使我们能够在给定t ≥ 1 的情况下将机器M 2的错误概率限制为 2 t,我们可以设置 α = −log 2 (4ε(1 − ε)) 并选择k ≥t / α。这样,我们就得到了一个在多项式时间内运行的算法,其错误概率为 2 p ( n )

We have assumed that ε < 1/2, so 4ε(1 − ε) < 1. Thus, the probability calculated above decreases exponentially with k , and so does the error probability of machine M 2 . To calculate a specific value of k that will allow us to bound the error probability of machine M 2 by 2 t for a given t ≥ 1, we can set α = −log 2 (4ε(1 − ε)) and choose kt /α. This way we obtain an algorithm that runs in polynomial time with error probability 2 p ( n ) .

首创性

First place

素数是大于 1 的整数,不能被除 1 及其本身之外的任何正整数整除。大于1的非素数称为合数。检查给定整数是否为素数的问题自古以来就为人所知,是深入研究的主题。目前有一个已知的多项式时间算法可以解决这个问题[4],但这里很难包含。相反,我们将描述一个更简单的概率素性测试算法,也以多项式时间运行。

A prime number is an integer greater than 1 that is not divisible by any positive integer other than 1 and itself. A nonprime number greater than 1 is called a composite number . The ancient problem of testing whether a given integer is prime has been the subject of intense research. A polynomial-time algorithm for this problem is now known [4], but it is too difficult to include here. Instead, we will describe a much simpler probabilistic algorithm for primality testing, also in polynomial time.

确定一个数字是否为素数的一种方法是尝试所有小于该数字的整数,看看它们是否是该数字的约数。该算法具有指数时间复杂度,因为数字的值相对于其长度呈指数关系。我们将在这里描述的概率素性测试算法以完备不同的方式工作。他不寻找除数。事实上,没有已知的概率多项式时间算法可以找到数字的除数。

One way to determine whether a number is prime is to try all the integers less than the number and see if they are divisors of the number. This algorithm has exponential time complexity, because the value of the number is exponential in its length. The probabilistic primality testing algorithm that we will describe here works in a completely different way. It does not look for divisors. In fact, there is no known probabilistic polynomial-time algorithm that finds the divisors of a number.

在讨论算法之前,我们先介绍一下数论中的一些概念。本节中考虑的所有数字都是整数。对于任何大于 1 的p ,如果两个数相差p的倍数,则我们说这两个数模 p 全等(有时它们等于模 p ) 。xy模p全等这一事实可写为x y (mod p )。我们假设x mod p是最小的非负数y,使得x == y (mod p )。每个数字与集合Z + p = {0, …, p − 1}中的某个元素模p同余。为了方便起见,我们还将引入符号Z p = {1, …, p −1}。我们还可以用其他同余数模p来引用这些集合的元素,例如我们可以将数字p − 1 称为 −1。

Before we discuss the algorithm, we introduce some concepts from number theory. All the numbers considered in this section are integers. For any p greater than 1, we say that two numbers are congruent modulo p (and sometimes equal modulo p ) if they differ by a multiple of p . The fact that x and y are congruent modulo p is written as x y (mod p ). We will assume that x mod p is the smallest nonnegative number y such that x y (mod p ). Every number is congruent modulo p to some element of the set Z + p = {0, …, p − 1}. For convenience, we will also introduce the notation Z p = {1, …, p −1}. We can also refer to elements of these sets by other numbers that are congruent modulo p , for example, we can refer to the number p − 1 as −1.

该算法使用的主要思想基于以下结果,称为费马小定理

The main idea used in this algorithm is based on the following result called Fermat's little theorem .

定理10.6

Theorem 10.6

如果p是素数且a Z + p,则a p −1 1 (mod p )。

If p is a prime number and a Z + p , then a p −1 1 (mod p ).

例如,如果p = 7 且 a = 2,则定理指出 2 (7−1) mod 7 应等于 1,因为 7 是素数。简单计算

For example, if p = 7 and a = 2, the theorem states that 2 (7−1) mod 7 should give 1, since 7 is prime. A simple calculation

2 (7−1) = 2 6 = 64 且 64 mod 7 = 1

2 (7−1) = 2 6 = 64 and 64 mod 7 = 1

证实了这个结果。假设我们选择p = 6 那么。

confirms this result. Suppose we choose p = 6 instead. Then

2 (6−1) = 2 5 = 32 且 32 mod 6 = 2

2 (6−1) = 2 5 = 32 and 32 mod 6 = 2

给出的结果与 1 不同,因此该定理意味着 6 不是素数。当然,我们已经知道这一点。然而,该方法表明 6 是一个合数,但没有指定它的约数。我们将费马小定理的证明留给问题 10.15 中的读者。

gives a result other than 1, so the theorem implies that 6 is not a prime number. Of course, we already knew that. Nevertheless, this method shows that 6 is a composite number without specifying its divisors. We leave the proof of Fermat's Little Theorem to the reader in Problem 10.15.

我们将这个定理视为一种“素性检验”,称为费马检验。当我们说数字p通过a 的费马测试时,我们的意思是a p −1 1 (mod p )。该定理指出,素数通过所有a Z + p的费马测试。我们注意到数字6没有通过某个费马测试,因此它不是素数。

We will treat this theorem as a kind of "primality test", called Fermat's test . When we say that the number p passes Fermat's test for a , we mean that a p −1 1 (mod p ). The theorem states that primes pass Fermat's test for all a Z + p . We noted that the number 6 fails a certain Fermat test, and so is not prime.

我们可以使用费马测试来提供素性算法吗?几乎。如果一个数字通过了所有小于它的数字的费马测试并且与它互质,我们将称该数字为伪素数。除了罕见的卡迈克尔数(它很复杂但通过了所有费马测试)之外,伪素数集与素数集相同。我们将首先介绍一个非常简单的概率多项式时间算法,该算法区分素数和合数(卡迈克尔数除外)。稍后我们将展示并分析用于检查数字素性的完整概率算法。

Can we use Fermat's test to give an algorithm for determining primality? Almost. A number is called pseudoprime if it passes Fermat's test for all numbers a less than it and coprime to it. Except for the rare Carmichael numbers , which are composite but pass all Fermat's tests, the set of pseudoprimes is identical to the set of primes. We begin by presenting a very simple probabilistic algorithm in polynomial time that distinguishes primes from composites except for the Carmichael numbers. We will later show and analyze the full probabilistic algorithm for determining primality.

检查一个数是否为伪素数的算法,执行所有费马测试,将花费指数时间。概率多项式时间算法的关键是观察到如果一个数不是伪素数,则它至少会失败一半的测试。 (现在,我们假设这个说法没有证据。在问题 10.16 中将有机会证明它。)该算法通过执行许多随机选择的测试来工作。如果其中一个失败,则该数字必须是合数。该算法包含一个确定错误概率的参数k 。

An algorithm for testing whether a number is pseudoprime that performs all of Fermat's tests would take exponential time. The key to a probabilistic algorithm that runs in polynomial time is the observation that if a number is not pseudoprime, then it fails at least half of the tests. (For now, accept this statement without proof. There will be an opportunity to prove it in Problem 10.16.) The algorithm works by performing a number of tests chosen at random. If any one fails, the number must be composite. The algorithm has a parameter k that specifies the probability of failure.

PSEUDOPRIME =“对于输入处给出的数字p

PSEUDOPRIME = "For a given input number p :

  1. 随机选择属于Z + p的数字a 1 , …, a k
  2. Randomly choose numbers a 1 , …, a k belonging to Z + p .
  3. 计算每个i的 ap −1 mod p
  4. Calculate a and p −1 mod p for each i .
  5. 如果所有计算值都是1,则接受;否则丢弃。”
  6. If all calculated values ​​are 1, accept ; otherwise reject ."

如果p是伪素数,它通过了所有测试,算法肯定会接受它。如果p不是伪素数,那么它最多可以通过一半的测试。在这种情况下,任何随机选择的测试都可以以最多A 的概率通过。因此,它通过所有k 个随机选择的测试的概率最多为 2 k。该算法在多项式时间内运行,因为模幂可以在多项式时间内计算(参见问题 7.13)。

If p is a pseudoprime, then it passes all tests and the algorithm will definitely accept. If p is not a pseudoprime, then it passes at most half of all tests. In that case, it can pass any randomly chosen test with probability at most A . The probability that it passes all k randomly chosen tests is therefore at most 2 k . The algorithm runs in polynomial time, since modulo exponentiation is computed in polynomial time (see Task 7.13).

为了将上述算法变成真正的素性检查算法,我们将引入一种更高级的测试,以避免与卡迈克尔数相关的问题。我们将使用以下性质:对于任何素数p,数 1 模p恰好有两个平方根:1 和 −1。对于许多合数,包括所有卡迈克尔数,至少有四个这样的根。例如,±1 和 ±8 是 1 模 21 的四个平方根。如果数字p通过了某个a的费马测试,算法会随机找到 1 模p根之一,并检查它是否等于 1 或−1。如果不是这种情况,我们就知道数字p不是素数。

To convert the above algorithm into a true primality test, we introduce a more advanced test that avoids the Carmichael number problem. We use the property that for any prime p, the number 1 modulo p has exactly two square roots, 1 and −1. For many composite numbers, including all the Carmichael numbers, there are at least four such roots. For example, ±1 and ±8 are the four square roots of 1 modulo 21. If p passes Fermat's test for some a , the algorithm randomly finds one of the roots of 1 modulo p and checks whether it is equal to 1 or −1. If it is not, we know that p is not prime.

当数p通过数a的费马检验时,我们可以计算 1 的平方根,因为 a p −1 mod p = 1,所以 a ( p −1)/2 mod p是 1 的平方根。这个值仍然等于 1,然后我们可以连续将指数除以 2,直到所得指数仍然是整数,每次检查是否得到 1 或 -1 或其他数字。在描述该算法之后,我们将提出该算法正确性的形式证明。我们选择k ≥ 1 作为参数,指定最大错误概率为 2 k

When p passes Fermat's test for a , we can compute square roots of 1, since a p −1 mod p = 1, so a ( p −1)/2 mod p is a square root of 1. If this value is still 1, we can successively divide the exponent by 2 as long as the resulting exponent remains an integer, checking each time whether we get 1 or −1, or some other number. We will give a formal proof of the correctness of this algorithm after we describe it. We choose k ≥ 1 as the parameter, which specifies that the maximum probability of error is 2 k .

PRIME =“对于输入数字p

PRIME = "For input number p :

  1. 如果p是偶数,则接受p = 2;否则丢弃
  2. If p is even, accept if p = 2; otherwise reject .
  3. 随机选择属于Z + p的数字a 1 , …, a k
  4. Randomly choose numbers a 1 , …, a k belonging to Z + p .
  5. 对于从 1 到k 的每个i
  6. For each i from 1 to k :
  7. 计算ap −1 mod p,如果结果与 1 不同则拒绝。
  8. Calculate a and p −1 mod p and reject if the result is different from 1.
  9. p − 1 = s ·2 l,其中s是奇数。
  10. Let p − 1 = s · 2 l , where s is an odd number.
  11. 计算值序列a i s ·2 0 , a i s ·2 1 , a i s ·2 2 , …, a i s ·2 lp
  12. Calculate the sequence of values ​​a i s 2 0 , a i s 2 1 , a i s 2 2 , …, a i s 2 l modulo p .
  13. 如果该序列的任何元素不等于 1,则找到最后一个非 1 元素,如果不等于 -1 则丢弃。
  14. If any element of this sequence is not equal to 1, find the last element not equal to 1 and discard if it is not equal to −1.
  15. 此时数字p已经通过了所有测试,即accept
  16. At this point, the number p has passed all the tests, i.e. accept ."

以下两个引理表明PRIME算法工作正常。显然,当p为偶数时,该算法是正确的,因此我们只考虑p为奇数时的情况。如果算法在步骤 4 或 7 中拒绝数字a i,我们就说a i(复杂性)见证。

The following two lemmas show that the PRIME algorithm works correctly. It is obvious that the algorithm is correct when p is even, so we will only consider the case when p is odd. We say that a i is a witness (of complexity) if the algorithm rejects in step 4 or 7 for a i .

引理 10.7

Lemma 10.7

如果p是奇素数,则 Pr[ PRIME算法接受p ] = 1。

If p is an odd prime number, then Pr[the PRIME algorithm accepts p ] = 1.

证明 首先,我们将证明如果p是素数,则没有证据证明它,并且算法的计算路径不会导致拒绝。如果a是满足步骤 4 中的条件的见证人,则 ( a p −1 mod p ) 1,因此费马小定理意味着数p是合数。如果a是满足步骤7中的条件的见证人,则存在属于Z p +的某个b,使得b ±1 (mod p ) 且b 2 1 (mod p )。由此可见 b 2 − 1 == 0 (mod p )。对 b 2 − 1 进行因式分解得到 ( b − 1)( b + 1) 0 (mod p ),这意味着对于某个正整数c , ( b − 1)( b + 1) = cp。由于b ±1 (mod p ),因此数字b − 1 和b + 1 都大于 0 且小于p。由此可见, p是合数,因为素数的倍数不能表示为两个小于其自身的数的乘积。

Proof We first show that if p is prime, then there is no witness for it and no path of the algorithm leads to rejection. If a is a witness satisfying the condition in step 4, then ( a p −1 mod p ) 1, and therefore by Fermat's little theorem p is composite. If a is a witness satisfying the condition in step 7, then there is some b in Z p + such that b ±1 (mod p ) and b 2 1 (mod p ) . This implies that b 2 − 1 0 (mod p ). Factoring b 2 − 1 gives ( b − 1)( b + 1) 0 (mod p ), which implies that ( b − 1)( b + 1) = cp for some positive integer c . Since b ±1 (mod p ), both numbers b − 1 and b + 1 are greater than 0 and less than p . It follows that p is a composite number, since a multiple of a prime number cannot be expressed as a product of two numbers less than itself.

下一个引理表明该算法以高概率识别合数。首先,我们将介绍数论中的一项重要的基本技术。如果两个数除了 1 之外没有公约数,则它们是互质的。中国剩余定理指出,如果pq是互质的,则集合Z pqZ p × Z q之间存在互唯一的对应关系。对于每个数字r Z pq都有一对 ( a , b ),其中a Z pb Z q,使得

The next lemma shows that the algorithm recognizes composite numbers with high probability. We first present an important basic technique of number theory. Two numbers are coprime if they have no common divisor other than 1. The Chinese remainder theorem states that if p and q are coprime, then there is a one-to-one correspondence between the sets Z pq and Z p × Z q . For each number r Z pq there is a pair ( a , b ), where a Z p and b Z q , such that

r = a (mod p ),

r a (mod p ),

r == b (mod q )。

r b (mod q ).

引理 10.8

Lemma 10.8

如果p是奇合数,则 Pr[ PRIME算法接受p ] ≤ 2 k

If p is an odd composite number, Pr[the PRIME algorithm accepts p ] ≤ 2 k .

证明 我们将证明,如果p是奇合数并且a是从集合Z p +中随机选择的数,则

Proof We will show that if p is an odd composite number and a is a randomly chosen number from the set Z p + , then

Pr[a 是证人] ≥ 1/2,

Pr[a is a witness] ≥ 1/2,

表明在集合Z + p中,见证人至少与非见证人一样多。为此,我们将为每个非见证号码找到一个唯一的见证人。

by showing that there are at least as many witnesses as non-witnesses in the set Z + p . To this end, we find a unique witness for each non-witness.

对于每个非见证数,算法第 6 步中计算的序列要么全为 1,要么在某个位置包含 -1,后跟 1。例如,1 本身不是第一类见证(序列将只包含 1),−1 也不是第二类见证,因为s是奇数,我们得到 (−1) s ·2 0 −1 和(−1) s · 2 1 1。在所有第二类非见证数中,我们找到一个-1 出现在序列中最高位置的数。令h为该数字,j为序列中出现 -1 的位置,序列中的位置从零开始编号。因此h s ·2 j == -1 (mod p )。

For each non-witness number, the sequence computed in step 6 of the algorithm consists of all ones or contains −1 in some position followed by ones. For example, 1 alone is not a witness of the first kind (the sequence will contain all ones), and −1 is not a witness of the second kind, since s is odd, and we get (−1) s · 2 0 −1 and (−1) s · 2 1 1. Among all the non-witness numbers of the second kind, we find one in which −1 appears in the highest position in the sequence. Let h be this number and let j be the position in the sequence in which −1 appears, with the positions in the sequence numbered from zero. Hence h s · 2 j −1 (mod p ).

由于p是合数,因此它要么是素数的幂,要么我们可以将p写为qr(两个相对素数)的乘积。我们首先考虑第二种情况。中国剩余定理意味着存在某个属于Z p的数t,使得

Since p is a composite number, it is either a power of a prime number, or we can write p as the product of q and r , two relatively prime numbers. We will consider the second case first. The Chinese remainder theorem implies that there is a number t belonging to Z p , such that

t h (mod q ) 和

t h (mod q ) and

t 1 (mod r )。

t 1 (mod r ).

因此

Hence

t s ·2 j −1 (mod q ) 和

t s ·2 j −1 (mod q ) and

t s ·2 j == 1 (mod r )。

t s · 2 j 1 (mod r ).

因此,我们看到t是见证人,因为t s ·2 j ±1 (mod p ),但 t s ·2 ( j + 1) 1 (mod p )。

We therefore see that t is a witness, since t s · 2 j ±1 (mod p ), but t s · 2 ( j + 1) 1 (mod p ).

一旦我们找到了一名证人,我们就能找到更多证人。我们通过两次观察证明dt mod p是每个非见证数d的唯一见证人。首先,由于j的值是如何选择的,因此 d s ·2 j ±1 (mod p ) 和 d s ·2 ( j +1) 1 (mod p ) 。因此,dt mod p是证据,因为 ( dt ) s ·2 j ±1 且 ( dt ) s ·2 ( j +1) eq 1 (mod p )。

Once we have one witness, we can find many more. We prove that dt mod p is a unique witness for every non-witness number d by two observations. First, d s · 2 j ±1 (mod p ) and d s · 2 ( j +1) 1 (mod p ) with respect to how j was chosen . So dt mod p is a witness since ( dt ) s · 2 j ±1 and ( dt ) s · 2 ( j +1) eq 1 (mod p ).

其次,对于不同的d 1d 2非证人,d 1 t mod p d 2 t mod p。这是因为t s ·2 ( j +1) mod p = 1,因此t · t s ·2 ( j +1) -1 mod p = 1。如果等式为td 1 mod p = td 2p,则

Secondly, for different d 1 and d 2 not being witnesses, d 1 t mod p d 2 t mod p . This follows from the fact that t s · 2 ( j +1) mod p = 1, so t · t s · 2 ( j +1) −1 mod p = 1. Therefore, if the equality td 1 mod p = td 2 mod p holds , then

d 1 = t · t s · 2 ( j +1) -1 d 1 mod p = t · t s · 2 ( j + 1) -1 d 2 mod p = d 2

d 1 = t · t s ·2 ( j +1) −1 d 1 mod p = t · t s ·2 ( j +1) −1 d 2 mod p = d 2 .

由此可见,证人的数量必须至少与非证人的数量一样多,当p不是素数的幂时,就结束了案件的分析。

It follows that the number of witnesses must be at least as large as the number of nonwitnesses, which ends the analysis of the case when p is not a power of a prime number.

对于素数幂的情况,我们有p = q e,其中q是素数且e > 1。令t = 1 + q e −1。使用二项式公式展开t p的值,我们得到

For the prime power case, we have p = q e , where q is prime and e > 1. Let t = 1 + q e −1 . Expanding the value of t p using the binomial formula, we get

t p = (1 + q e −1 ) p = 1 + p · q e −1 + q e −1的高次幂的倍数,

t p = (1 + q e −1 ) p = 1 + p q e −1 + multiples of higher powers of q e −1 ,

与 1 模p一致。因此,t是步骤 4 中的见证,因为如果t p −1 eq 1 (mod p ),我们将得到t p eq t 1 (mod p )。与前一个案例一样,我们可以利用这个证人来找到许多其他证人。如果数字d不是见证人,那么我们得到d p −1 1 (mod p ),但是dt mod p是见证人。此外,如果d 1d 2不同且不是见证人,则d 1 t mod p d 2 t mod p。否则我们会得到

which is congruent to 1 modulo p . Hence t is the witness from step 4, since if t p −1 1 (mod p ), then we would get t p t 1 (mod p ). As in the previous case, we can use this witness to find many others. If the number d is not a witness, then we get d p −1 1 (mod p ), but then dt mod p is a witness. Moreover, if d 1 and d 2 are different and are not witnesses, then d 1 t mod p d 2 t mod p . Otherwise, we would get

d 1 = d 1 · t · t p -1 mod p = d 2 · t · t p -1 mod p = d 2

d 1 = d 1 · t · t p −1 mod p = d 2 · t · t p −1 mod p = d 2 .

所以我们看到证人的数量必须至少与非证人的数量一样多,这样就完成了证明。

We therefore see that the number of witnesses must be at least as large as the number of non-witnesses, which completes the proof.

所提出的算法及其分析使我们得出以下定理。设PRIMES = { n : n是二进制表示的质数}。

The presented algorithm and its analysis lead us to the following theorem. Let PRIMES = { n : n is a prime number in binary notation}.

定理10.9

Theorem 10.9

PRIMES BPP。

PRIMES BPP.

请注意,概率素性检查算法是一种单方面错误算法。当该算法拒绝输入(返回拒绝)时,我们知道该数字必须是合数。当输出为accept时,我们只知道该数字可以是素数或合数。因此,只有当输入的数字是合数时,才会出现错误的响应。单边误差性质在许多概率算法中很常见,因此为其定义了一个特殊的复杂度类RP。

Note that the probabilistic primality algorithm is a one-sided error algorithm . When this algorithm rejects the input (returns reject ), we know that the number must be composite. When the output is accept , we only know that the number can be either prime or composite. Thus, an incorrect answer can only occur if the input is composite. The one-sided error property is common among many probabilistic algorithms, so a special complexity class RP has been defined for it.

定义10.10

Definition 10.10

RP 是由概率多项式时间图灵机解析的一类语言,它以至少等于 1/2 的概率接受属于该语言的单词,并以等于 1 的概率拒绝不属于该语言的单词。

RP is a class of languages ​​that are resolved by probabilistic Turing machines running in polynomial time, which accept words that belong to the language with probability at least 1/2 and reject words that do not belong to the language with probability 1.

通过使用类似于引理 10.5 中使用的(实际上更简单)的提升技术,我们可以使错误概率呈指数级小,并且仍然保持多项式运行时间。所提出的算法表明COMPOSITES RP。

We can make the error probability exponentially small and still maintain polynomial running time by using a boosting technique analogous to the one used in Lemma 10.5 (and in fact simpler). The algorithm presented shows that COMPOSITES RP.

只读一次分支程序

Read-once branching programs

分支程序是复杂性理论和某些实际应用(例如计算机辅助设计)中使用的计算模型。该模型代表一个决策过程,该过程检查输入变量的值并根据获得的响应确定进一步的操作。我们将这个决策过程呈现为一个图,其顶点对应于在过程中给定点读取的特定变量。

A branching program is a model of computation used in complexity theory and in some practical applications, such as computer-aided design. This model represents a decision process that examines the values ​​of input variables and determines further action based on the answers obtained. We represent this decision process as a graph whose vertices correspond to specific variables read at a given point in the process.

在本节中,我们将研究检查两个分支程序是否等效的复杂性。一般情况下,这个问题是coNP完备的。然而,如果我们对分支程序的类别施加一些自然约束,我们就可以提出一种在多项式时间内运行的概率等价测试算法。该算法特别有趣有两个原因。首先,对于这个问题,还没有已知的多项式时间算法,因此这将是一个使用随机性来显着扩展可以进行有效成员资格测试的语言类别的示例。其次,该算法引入了一种将非逻辑值分配给通常是逻辑的变量的技术,以便能够分析这些变量的某些逻辑函数的行为。正如我们将在 10.4 节中看到的,这种技术在交互式命令系统中得到了巨大的成功。

In this section, we examine the complexity of testing whether two branching programs are equivalent. In general, this problem is coNP-complete. However, if we impose some natural constraints on the class of branching programs, we can provide a probabilistic polynomial-time equivalence testing algorithm. This algorithm is particularly interesting for two reasons. First, no polynomial-time algorithm is known for this problem, so it is an example of using randomness to significantly extend the class of languages ​​for which membership testing is efficient. Second, this algorithm introduces a technique for assigning nonlogical values ​​to variables that are usually logical, in order to analyze the behavior of some logical functions for these variables. This technique has been used with great success in interactive proof systems, as we will see in Section 10.4.

定义10.11

Definition 10.11

分支程序更常见的名称是“二元决策图”)是一个有向无环图2,其中除了两个输出顶点(其标签为 0 或 1)之外,所有顶点都用变量进行标记。用变量标记的顶点称为查询顶点。每个查询顶点都有两条传出边:一条带有标签 0,另一条带有标签 1。输出顶点没有传出边。分支程序的顶点之一被标记为起始顶点。

A branching program ( more commonly called a "binary decision diagram") is a directed acyclic graph 2 in which all vertices are labeled with variables except the two output vertices , which are labeled 0 or 1. The vertices labeled with variables are called query vertices . Each query vertex has two outgoing edges, one labeled 0 and the other labeled 1. Output vertices have no outgoing edges. One of the vertices of a branching program is labeled as the start vertex.

分支程序指定如下逻辑函数。让我们对查询顶点中出现的变量进行任何评估。从初始顶点开始,我们遵循一条定义的路径,从每个顶点开始,我们沿着其标签对应于给定顶点中读取的变量值的边,直到输出顶点之一。结果就是该顶点的标签。图 10-12 显示了两个分支程序的示例。

A branching program defines a logical function in the following way. Consider any valuation of variables appearing at query vertices. Starting at the initial vertex, we follow a path defined by traversing from each vertex the edge whose label matches the value of the variable read at that vertex to one of the output vertices. The result is the label of that vertex. Figure 10-12 shows two examples of branching programs.

分支程序与 L 类的关系类似于逻辑电路与 P 类之间的关系。在问题 10.17 中,应该表明具有多项式数量的顶点的分支程序可用于检查单词与语言的从属关系​​字母表 {0,1} 上方属于 L 类

Branch programs are related to the class L in a way analogous to the relationship between logical circuits and the class P. In Problem 10.17, show that branch programs with a polynomial number of vertices can be used to check whether words belong to languages ​​over the alphabet {0,1} that belong to the class L.

如果两个分支程序定义相同的函数,则它们是等效的。在问题10.21中,应该证明测试分支程序等价性的问题是coNP完备的。这里我们将处理分支程序的有限形式。一次读取分支程序在从起始顶点到输出顶点的每条路径上最多读取一次每个变量的程序。图 10.12 中所示的两个程序都具有只读一次属性。让

Two branching programs are equivalent if they define the same functions. In Problem 10.21, show that the problem of testing the equivalence of branching programs is coNP-complete. Here we deal with the restricted form of branching programs. A branching program with a read-once branch is a program that can read each variable at most once on each path from the start to the exit node. Both programs in Figure 10.12 have the read-once property. Let

EQ ROBP ={ < B 1 , B 2 >B 1B 2是等价的一次读取分支程序}。

EQ ROBP ={ B 1 , B 2 : B 1 and B 2 are equivalent read-once branching programs}.

10.12

两个只读分支程序

Figure 10.12

Two read-once branching programs

定理10.13

Theorem 10.13

EQ ROBP问题属于 BPP 类。

The EQ ROBP problem belongs to the BPP class.

证明的概念首先,我们可以为程序B 1B 2中出现的 变量x 1 , ..., x m分配随机值,并计算该分配的程序值。如果B 1B 2返回此分配的匹配结果,我们接受,否则拒绝。然而,这个策略不会起作用,因为两个非等价的分支程序可能只对 2 m 个可能的分配中的一个分配产生不同的结果。选择这个特定任务的概率是指数级的小。因此,即使B 1B 2不等价,我们也可能以很高的概率接受,这是不可接受的。

The Concept of the Proof First, we can assign random values ​​to variables x 1 , …, x m occurring in programs B 1 and B 2 and compute the program values ​​for this assignment. We accept if B 1 and B 2 return consistent results for this assignment, and reject otherwise. However, this strategy will not work, because two non-equivalent programs with branches can give different results only for a single assignment out of 2 m possible. The probability of choosing this particular assignment is exponentially small. It could turn out that we accept with high probability even when B 1 and B 2 are not equivalent, which is unacceptable.

相反,我们将通过向变量随机分配非布尔值并以适当定义的方式计算与程序B 1B 2相对应的函数的结果来更改此策略。我们将能够证明,如果程序B 1B 2不等价,这种随机计算很可能会给出不同的结果。

Instead, we will modify this strategy by randomly assigning values ​​to the variables that are not Boolean values ​​and computing the results of the functions corresponding to the programs B 1 and B 2 in an appropriately defined way. We will be able to show that if the programs B 1 and B 2 are not equivalent, then with high probability such random computations will produce different results.

证明我们将变量x 1 , ..., x m的多项式分配给具有分支B 的 程序的顶点和边,如下所示。我们将等于 1 的常量函数分配给起始顶点如果为带有标签x 的顶点分配一个多项式p,我们将多项式xp分配给带有标签 1 的出边,并且为带有标签 0 的边分配多项式 (1)。 − x ) p。如果进入某个顶点的边分配有任何多项式,我们将这些多项式的和分配给该顶点。最后,分配给标签为 1 的输出顶点的多项式也分配给整个分支程序。我们现在可以提出EQ ROBP问题的概率多项式时间算法。令F为包含至少 3 m 个元素的有限域。

Proof We assign polynomials of variables x 1 , …, x m to the vertices and edges of a branching program B as follows. We assign a constant function equal to 1 to the initial vertex. If the vertex labeled x is assigned a polynomial p , we assign the polynomial xp to the outgoing edge labeled 1, and we assign the polynomial (1 − x ) p to the edge labeled 0. If the edges entering a vertex are assigned some polynomials, we assign the sum of these polynomials to that vertex. Finally, the polynomial that was assigned to the outgoing vertex labeled 1 is also assigned to the entire branching program. We can now present a probabilistic polynomial-time algorithm for the problem EQ ROBP . Let F be a finite field with at least 3m elements .

D = "对于输入词B 1 , B 2 ,其中B 1B 2是两个只读分支程序:

D = "For input word B 1 , B 2 , where B 1 and B 2 are two read-once branching programs:

  1. 如上所述,为程序B 1B 2构造多项式p 1p 2 。
  2. Construct the polynomials p 1 and p 2 for the programs B 1 and B 2 in the manner described above.
  3. 从字段F中随机选择元素a 1a m
  4. Randomly choose elements a 1 to a m from the field F .
  5. 计算变量a 1a m的值的多项式p 1p 2的值。
  6. Calculate the values ​​of the polynomials p 1 and p 2 for the values ​​of variables a 1 to a m .
  7. 如果p 1 ( a 1 , …, a m ) = p 2 ( a 1 , …, a m ),接受;否则丢弃。”
  8. If p 1 ( a 1 , …, a m ) = p 2 ( a 1 , …, a m ), accept ; otherwise reject ".

该算法在多项式时间内运行,因为我们可以计算与分支程序相对应的多项式的值,而无需实际构造多项式。我们将证明该算法以不大于B 的错误概率解决EQ ROBP问题。

This algorithm runs in polynomial time, since we can compute the value of the polynomial corresponding to the branching program without actually constructing the polynomial. We will show that this algorithm solves the EQ ROBP problem with an error probability no greater than B .

让我们检查一次读取分支程序B与其指定的多项式p之间的关系。请注意,对于对B 的变量进行逻辑值的任何赋值,分配给其顶点的所有多项式都会产生值 0 或 1。产生值 1 的多项式是位于该赋值的计算路径中的多项式。因此,我们可以看到,当我们给变量赋值逻辑值时,程序B和多项式p给出了相同的结果。类似地,由于程序B是一次性读取的,我们可以将p写为y 1 y 2 y m形式的因子(项)之和,其中每个y i等于x i、 (1 − x i ) 或1,其中每一项对应于程序B中从起始顶点到标签为 1 的输出顶点的路径。当该路径不包含变量x i时,会出现y i = 1 的情况。

Let us examine the relationship between a read-once branching program B and its assigned polynomial p . Note that for any assignment of Boolean values ​​to the variables of B, all polynomials assigned to its vertices evaluate to either 0 or 1. The polynomials that evaluate to 1 are those that lie on the computational path for that assignment. We see that program B and the polynomial p yield the same result when we assign Boolean values ​​to the variables. Similarly, since program B is read-once, we can write p as a sum of factors (terms) of the form y 1 y 2 y m , where each y i is equal to x i , (1 − x i ) or 1, with each term corresponding to a path in program B from the start vertex to the output vertex with label 1. The case y i = 1 occurs when this path does not contain the variable x i .

让我们取包含y i等于 1 的多项式p的一项,并将其分为两项之和:一项为y i = x i,另一项为y i = (1− x i )。我们将得到等效多项式 1 = x i + (1 − x i )。我们继续划分这些项,直到每个y i都是x i或 (1 − x i )的形式。最终结果是一个等效多项式q ,其中包含程序B值为 1 的每个赋值的一项。现在我们可以分析算法D的行为。

Take a polynomial term p containing y i equal to 1 and divide it into the sum of two terms: one with y i = x i , and the other with y i = (1− x i ). We obtain an equivalent polynomial, since 1 = x i + (1 − x i ). We continue dividing terms until each y i is either of the form x i or (1 − x i ). The final result is an equivalent polynomial q , which contains a term for each assignment for which program B evaluates to 1. We can now analyze the behavior of algorithm D .

首先,我们将证明如果B 1B 2相等,则D将始终被接受。如果分支程序是等效的,则它们对于完备相同的分配返回 1。因此,多项式q 1q 2相等,因为它们包含相同的项。因此,对于每个分配, p 1p 2相等。

First, we show that if B 1 and B 2 are equivalent, then D will always accept. If the branching programs are equivalent, they return the value 1 for exactly the same assignments. Consequently, the polynomials q 1 and q 2 are equal, since they contain identical terms. Thus, p 1 and p 2 are equal for every assignment.

其次,我们证明如果B 1B 2不等价,那么算法D将以至少 2/3 的概率拒绝。这个结论直接来自引理 10.15。

Second, we show that if B 1 and B 2 are not equivalent, then algorithm D rejects with probability at least 2/3. This conclusion follows directly from Lemma 10.15.

该证明基于以下引理,涉及随机找到多项式根的概率作为多项式包含的变量数量、这些变量的阶数以及该多项式所在域的大小(元素数量)的函数。多项式被定义。

This proof relies on the following lemmas concerning the probability of randomly finding a root of a polynomial as a function of the number of variables it contains, the degree of these variables, and the size (number of elements) of the field over which the polynomial is defined.

引理10.14

Lemma 10.14

对于每个d ≥ 0,一个变量xd次多项式要么最多有d 个根,要么处处等于 0。

For every d ≥ 0, a polynomial of degree d in one variable x either has at most d roots or is everywhere equal to 0.

证明 我们将对d应用归纳法。

Proof We use induction on d .

基本步骤:我们将证明d = 0时的命题。0次多项式是常数。如果该常数不等于 0,则多项式无根。

Basic Step: We will prove the thesis for d = 0. A polynomial of degree 0 is a constant. If this constant is not equal to 0, the polynomial has no roots.

归纳步骤:我们假设d − 1的命题为真,并证明它对于d成立。如果p是d次非零多项式且有根a,则多项式 − a 除以多项式p且无余数。那么p /( x −a) 是d −1次的非零多项式,并且根据归纳假设最多有d −1 个根。

Inductive step: We assume the thesis for d − 1 and prove that it holds for d . If p is a nonzero polynomial of degree d and has root a , then the polynomial − a divides the polynomial p without remainder. Then p /( x − a) is a nonzero polynomial of degree d −1 and has at most d −1 roots by the inductive assumption.

引理 10.15

Lemma 10.15

F为具有f 个元素的有限域,令p为变量x 1x m的非零多项式,其中每个变量的次数至多为d。如果我们随机选择属于F的数字a 1a m,则 Pr[ p ( a 1 , …, a m ) = 0] ≤ md / f

Let F be a finite field with f elements and let p be a nonzero polynomial in variables x 1 to x m ​​, where each variable has degree at most d . If we choose random numbers a 1 to a m belonging to F , then Pr[ p ( a 1 , …, a m ) = 0] ≤ md / f .

证明 我们将对m应用归纳法。

Proof We use induction on m .

基本步骤:证明m = 1。由引理 10.14 可知,多项式p至多有d 个根,因此a 1是其中之一的概率为d / f

Basic Step: Proof for m = 1. By Lemma 10.14, the polynomial p has at most d roots, so the probability that a 1 is one of them is d / f .

归纳步骤:我们假设该命题对于m − 1 成立,并证明它对于m成立。令x 1为多项式p的变量之一。对于每个id,令p i为由包含x i 1的多项式p的项组成的多项式,但在删除该单项式x i 1之后。然后

Inductive step: We assume that the thesis holds for m − 1 and we will show that it is true for m . Let x 1 be one of the variables of the polynomial p . For each id let p i be a polynomial composed of terms of the polynomial p containing x i 1 , but after removing this monomial x i 1 . Then

p = p 0 + x 1 p 1 + x 2 1 p 2 + + x d 1 p d

p = p 0 + x 1 p 1 + x 2 1 p 2 + + x d 1 p d .

如果p ( a 1 , …, a m ) = 0,则可能发生两种情况之一。要么所有p i的值为 0,要么有些p i不等于 0,并且a 1是通过计算多项式p 0p d的值来替换而得到的一个变量的多项式的根​a 2a m表示其余变量。

If p ( a 1 , …, a m ) = 0, then one of two cases can occur. Either all p i are 0, or some p i is not equal to 0 and a 1 is a root of a polynomial in one variable obtained by evaluating the polynomials p 0 to p d by substituting the values ​​a 2 to a m for the remaining variables .

为了估计第一种情况的概率,我们可以注意到其中一个多项式pj必须非零,因为整个多项式p都是非零的。因此,所有p i的值为 0的概率至多是p j的值为 0 的概率。通过归纳假设,这至多为 ( m − 1) d / f,因为p j至多有m − 1个变量。

To estimate the probability of the first case, we can note that one of the polynomials p j must be nonzero, since the entire polynomial p is nonzero. Therefore, the probability that all p i are 0 is at most the probability that p j is 0. By the inductive assumption, this is at most ( m − 1) d / f , since p j has at most m − 1 variables.

要估计第二种情况的概率,请注意,如果某个多项式p i不具有值 0,那么当为变量从a 2a m赋值时,多项式p会简化为非零多项式一个变量x 1。在基本步骤中,我们证明了1是此类多项式的根的概率至多为d / f

To estimate the probability of the second case, note that if some polynomial p i does not equal 0, then when assigning values ​​from a 2 to a m to variables, the polynomial p reduces to a nonzero polynomial in one variable x 1 . In the basic step, we showed that the probability that a 1 is a root of such a polynomial is at most d / f .

因此,值a 1a m是多项式的根的概率至多为 ( m − 1) d / f + d / f = md / f

Hence, the probability that the values ​​a 1 to a m are a root of the polynomial is at most ( m − 1) d / f + d / f = md / f .

我们将以一个与算法中随机性的使用相关的更重要的问题来结束本小节。在我们的分析中,我们假设算法是使用真正的随机性来实现的。然而,实现真正的随机性可能很困难(或不可能),因此通常使用伪随机生成器,它们是结果看似随机的确定性算法。尽管任何确定性过程的输出永远不会是真正随机的,但其中一些过程产生的结果具有随机生成结果的某些属性。旨在利用随机性的算法可能与这些伪随机生成器同样有效,但证明这一点通常要困难得多。事实上,有时概率算法不能很好地与某些伪随机生成器配合使用。复杂的伪随机生成器已经被开发出来,只要存在单向函数,在多项式时间内运行的任何测试都无法将其结果与真正的随机生成器区分开来。 (我们在 10.6 节中讨论了单向函数。)

We will conclude this section with one more important issue related to the use of randomness in algorithms. In our analysis, we have assumed that algorithms are implemented using true randomness. However, achieving true randomness can be difficult (or impossible), so it is common to use pseudorandom generators , deterministic algorithms whose outputs appear to be random. Although the output of any deterministic procedure will never be truly random, some of these procedures produce outputs that have some of the properties of randomly generated outputs. Algorithms designed to use randomness may work equally well with these pseudorandom generators, but proving this is generally much more difficult. In fact, sometimes probabilistic algorithms do not work well with certain pseudorandom generators. Advanced pseudorandom generators have been developed whose outputs are indistinguishable from true randomness by any polynomial-time test, provided that one-way functions exist. (Section 10.6 includes a discussion of one-way functions.)

10.3

交替

10.3

Alternations

交替是非确定性的概括,已被证明对于理解计算复杂性类别之间的关系和确定特定问题的计算复杂性都很有用。使用交替,我们可以简化复杂性理论的各种证明,并显示复杂性的时间测量和记忆测量之间令人惊讶的联系。

Alternation is a generalization of nondeterminism that has proven useful both for understanding the relationships between classes of computational complexity and for determining the computational complexity of specific problems. Using alternation, we can simplify various proofs of complexity theory and show surprising connections between time and memory measures of complexity.

与非确定性算法类似,交替算法可以包含将进程拆分为多个子进程的指令。这些类型的算法之间的区别在于接受的方法。如果任何启动的进程接受,则非确定性计算会导致接受。当交替计算被分成多个进程时,有两种可能性。当至少一个子进程接受时,该算法可以接受,但我们也可以要求当所有子进程都接受时才接受。

An alternating algorithm may contain instructions to split a process into multiple child processes, just like a nondeterministic algorithm. The difference between these types of algorithms lies in the way acceptance occurs. A nondeterministic computation results in acceptance if any of the initiated processes accept. When an alternating computation is split into multiple processes, there are two possibilities. The algorithm may accept if at least one of the child processes accepts, or we can require that acceptance occur if all of the child processes accept.

交替计算和非确定性计算之间的差异可以可视化为表示调用进程的分支结构的树。每个顶点代表给定进程的配置。在非确定性计算中,每个顶点为其后代的结果计算一个替代(或运算)。这对应于通常的非确定性接受模式,在该模式中,只要其至少一个子进程接受,进程就接受。在交替计算中,顶点可以计算合取或析取(AND 或 OR 运算)。这对应于接受模式从进程在接受其任何子进程时接受的接受模式到需要所有子进程接受的接受模式的改变或交替。我们定义交替图灵机如下。

The differences between alternating and nondeterministic computations can be visualized by representing them as trees representing the branching structure of the invoked processes. Each node represents the configuration of a given process. In nondeterministic computations, each node computes an alternative (OR operation) for the results of its descendants. This corresponds to the usual nondeterministic acceptance mode, in which a process accepts if at least one of the descendants accepts. In alternating computations, nodes can compute conjunctions or alternatives (AND or OR operations). This corresponds to a change, or alternation, of the acceptance mode from one in which a process accepts if it accepts any of the descendants to one in which acceptance by all descendants is required. An alternating Turing machine is defined as follows.

定义10.16

Definition 10.16

交替图灵机是具有附加功能的非确定性图灵机。它的状态,除了状态q Acceptq Reject之外分为两组:普遍状态存在状态。确定性计算树的每个顶点分配标签∧,具体取决于相应的配置是否包含通用状态或存在状态。如果树中的一个节点被标记为并且它的所有子顶点都在接受,或者如果它被标记为并且它的至少一个子顶点都在接受,如果计算树的根正在接受输入词,则该输入词被接受。

An alternating Turing machine is a nondeterministic Turing machine with additional functionality. Its states, except for the states q accept and q reject , are divided into two groups: universal states and existential states . When we run an alternating Turing machine on an input word, we assign a label ∧ or to each vertex of the nondeterministic computation tree, depending on whether the corresponding configuration contains a universal or existential state. We say that a vertex of the tree is accepting if it is labeled and all of its children are accepting, or if it has a label and at least one of its children is accepting. An input word is accepted if the root of the computation tree for it is accepting.

下图显示了非确定性和交替计算树。我们用标记交替计算树中的顶点,以显示它们为子顶点的值计算什么函数。

The following figure shows nondeterministic and alternating computation trees. We have labeled the nodes in an alternating computation tree with or to show what function they compute for the values ​​at the child nodes.

10.17

非确定性和交替计算树

Figure 10.17

Nondeterministic and alternating computation trees

交替计算中的时间和内存

Time and memory in alternating calculations

我们以与非确定性图灵机相同的方式定义此类机器的时间和内存复杂性:通过选择任何计算路径中使用的最大时间或内存。我们定义交替机器的时间和内存复杂度类别如下。

We define the time and memory complexity of such machines in the same way as for nondeterministic Turing machines: by choosing the maximum time or memory used in any computation path. We define the time and memory complexity classes for alternating machines as follows.

定义10.18

Definition 10.18

ATIME( t ( n )) = {L : L 是交替图灵机在时间O ( t ( n )) 内解析的语言}。

ATIME( t ( n )) = {L : L is a language that is decided by an alternating Turing machine in time O ( t ( n ))}.

ASPACE( f ( n )) = {L : L 是交替图灵机在内存O ( f ( n ))中解析的语言}。

ASPACE( f ( n )) = {L : L is a language decided by an alternating Turing machine in space O ( f ( n ))}.

我们将 AP、APSPACE 和 AL 类定义为分别通过多项式时间、多项式内存和对数内存中交替图灵机来解析的语言类。

We define the classes AP, APSPACE, and AL as the classes of languages ​​that are decided by alternating Turing machines in polynomial time, polynomial memory, and logarithmic memory, respectively.

10.19

Example 10.19

同义反复是一个逻辑公式,其变量的每次评估值为 1。设TAUT = {Φ〉 : Φ是同义反复}。下面的交替算法表明TAUT问题属于 AP 类。

A tautology is a logical formula that has the value 1 for every valuation of its variables. Let TAUT = {Φ〉 : Φ is a tautology}. The following alternating algorithm shows that the TAUT problem belongs to the class AP.

“对于输入词〈Φ〉

"For input word 〈Φ〉 :

  1. 普遍选择公式Φ的所有变量评估。
  2. Universally select all evaluations of the variables of the formula Φ .
  3. 对于每个特定变量估值,计算公式Φ的值。
  4. For each specific valuation of variables, calculate the value of the formula Φ .
  5. 如果Φ公式返回 1,则接受;否则丢弃。”
  6. If formula Φ returns value 1, accept ; otherwise reject ".

在该算法的步骤 1 中,我们使用通用分支非确定性地选择公式Φ的变量的所有评估。这意味着与这些评估相对应的所有计算路径都必须被机器接受。在步骤 2 和 3 中,我们确定性地检查为特定计算路径选择的估值是否满足公式。因此,如果该算法检查所有评估均得到满足,则该算法接受输入单词。

In step 1 of this algorithm, we nondeterministically select all valuations of the formula variables Φ , using a universal branch. This means that all computation paths corresponding to these valuations must be accepting for the machine to accept. In steps 2 and 3, we deterministically check whether the valuation chosen for a particular computation path satisfies the formula. Thus, this algorithm accepts the input word if it checks that all valuations are satisfying.

请注意,TAUT问题属于 coNP 类。事实上,您可以使用类似于本示例中所示的算法来证明 coNP 类中的每个问题都在 AP 类中。

Note that the TAUT problem belongs to the class coNP. In fact, one can show that every problem belonging to the class coNP is in the class AP using an algorithm similar to the one shown in this example.

10.20

Example 10.20

在这个例子中,我们将展示一种属于 AP 类的语言,不知道它是属于 NP 还是 coNP 类。回想一下第 328 页的问题 7.46 中定义的MIN-FORMULA语言。下面给出的算法表明MIN-FORMULA语言属于 AP 类。

In this example, we show a language that belongs to the class AP but is not known whether it belongs to the class NP or coNP. Recall the language MIN-FORMULA defined in Problem 7.46 on page 328. The algorithm presented below shows that the language MIN-FORMULA belongs to the class AP.

“对于输入词〈Φ〉

"For input word 〈Φ〉 :

  1. 普遍选择所有比Φ公式短的φ公式。
  2. Universally select all φ formulas that are shorter than the Φ formula .
  3. 存在地选择公式Φ的变量的估值。
  4. Existentially choose the valuation of the variables of the formula Φ .
  5. 计算本次估值的ΦΦ的值。
  6. Calculate the values ​​of Φ and φ for this valuation.
  7. 如果公式返回不同的值,则接受。如果它们返回相同的值,则丢弃。
  8. Accept if formulas return different values. Reject if they return the same value."

该算法从在步骤 1 中选择所有较短公式的通用分支开始,然后切换到存在分支以在步骤 2 中选择值分配。术语交替来自于改变 的能力,即在之间切换机器的操作模式通用分支和存在分支。

This algorithm starts in step 1 with a universal branch selecting all shorter formulas, and then switches to an existential branch to select the value assignment in step 2. The term alternation is derived from the ability to alternate , or switch the mode of operation of the machine between the universal branch and the existential branch.

交替提供了复杂性的时间测量和记忆测量之间的重要联系。粗略地说,以下定理显示了交替计算的时间与确定性计算的内存之间的等价性,前提是这些资源是多项式相关的;第二个等价关系涉及用于交替计算的内存和用于确定性计算的运行时间,前提是时间比内存多得多。

Alternation provides an important connection between time and memory complexity measures. Roughly speaking, the following theorem shows an equivalence between time for alternating computations and memory for deterministic computations, provided that these resources are polynomially related; the second equivalence concerns memory for alternating computations and running time for deterministic computations, provided that there is exponentially more time than memory.

定理10.21

Theorem 10.21

对于f ( n ) ≥ n,以下条件成立:ATIME( f ( n )) SPACE( f ( n )) ATIME( f 2 ( n ))。

For f ( n ) ≥ n the inclusions ATIME( f ( n )) SPACE( f ( n )) ATIME( f 2 ( n )) hold.

对于f ( n ) ≥ log n,有 ASPACE( f ( n )) = TIME(2 O( f ( n )) )。

For f ( n ) ≥ log n we have ASPACE( f ( n )) = TIME(2 O( f ( n )) ).

该定理的结果是等式 AL = P、AP = PSPACE 和 APSPACE = EXPTIME。证明包含在下面提出的四个引理中。

A consequence of this theorem is the equalities AL = P, AP = PSPACE, and APSPACE = EXPTIME. The proof is given by the four lemmas that follow.

引理 10.22

Lemma 10.22

对于f ( n ) ≥ n,有 ATIME( f ( n )) SPACE( f ( n ))。

For f ( n ) ≥ n we have ATIME( f ( n )) SPACE( f ( n )).

证明我们将把在时间O ( f ( n )) 中运行的交替机器M转换为在内存O ( f ( n ))中运行的确定性机器 S。机器S模拟机器M的操作如下。对于输入单词w,机器 S 在机器M的计算树中执行深度优先搜索,以确定树的哪些节点正在接受。如果机器 S 确定对应于机器M的初始配置的树的根是接受顶点,则机器 S 接受。

Proof We transform an alternating machine M running in time O ( f ( n )) into a deterministic machine S running in memory O ( f ( n )). Machine S simulates the operation of machine M as follows. For an input word w, machine S performs a depth-first search of the computation tree of machine M to determine which vertices of that tree are accepting. Machine S then accepts if it determines that the root of the tree corresponding to the initial configuration of machine M is an accepting vertex.

机器 S 需要内存来存储深度优先搜索中进行的递归调用的堆栈。每一级递归都需要编写一个配置。递归深度就是机器M的时间复杂度。每个配置使用O ( f ( n )) 内存, M 的时间复杂度为O ( f ( n ))。由此可见,机器 S 使用内存O ( f 2 ( n ))。

Machine S needs memory to store the stack of recursive calls performed in depth-first search. Each level of recursion requires storing one configuration. The depth of recursion is the time complexity of machine M . Each configuration uses O ( f ( n )) of memory, and the time complexity of M is O ( f ( n )). It follows that machine S uses O ( f 2 ( n )) of memory .

我们可以通过注意到机器 S 不需要存储每个递归调用的整个配置来提高内存复杂性。相反,它只能存储机器M为从之前的配置实现此配置而做出的非确定性选择。然后,S 机器可以通过从头开始重复计算并遵循记住的“路标”来重新创建此配置。此更改将每次递归调用的内存使用量减少到一个常量。因此,总内存使用量现在为O ( f ( n ))。

We can improve the memory complexity by noting that machine S does not have to store the entire configuration for each recursive call. Instead, it can store only the nondeterministic choice that machine M makes to reach that configuration from the previous one. Then machine S can recreate that configuration by repeating the computation from the beginning and following the stored “signposts.” This change reduces the memory usage to a constant amount for each recursive call. Thus, the total memory usage is now O ( f ( n )).

引理10.23

Lemma 10.23

对于f ( n ) ≥ n,有 SPACE( f ( n )) ATIME( f 2 ( n ))。

For f ( n ) ≥ n we have SPACE( f ( n )) ATIME( f 2 ( n )).

证明我们从在内存O ( f ( n )) 中运行的确定性机器M开始,并构建在时间 O( f 2 ( n ))中运行的替代机器 S 来模拟M。这种方法类似于萨维奇定理(定理 8.5)的证明中使用的方法,我们构造了一个过程来解决一般情况下的可达性问题。

Proof We start with a deterministic machine M running in memory O ( f ( n )) and construct an alternating machine S running in time O( f 2 ( n )) simulating M . This approach is analogous to that used in the proof of Savitch's theorem (Theorem 8.5), where we constructed a procedure that solves the reachability problem in the general case.

在可达性问题中,我们得到了机器M的配置c 1c 2以及数字t。我们需要确定机器M是否可以在不超过t步内从配置c 1转到c 2。该问题的交替过程首先执行存在分支来猜测位于从c 1c 2 的路径中途的配置cm。然后,它普遍分支为两个过程:一个过程递归地检查是否有可能在不超过t /2 步的时间内从c 1c m,另一个过程检查是否可以在不超过t 的时间内从cmc m /2 步。

In the reachability problem, we were given configurations c 1 and c 2 of machine M and a number t . We needed to determine whether machine M can go from configuration c 1 to c 2 in no more than t steps. The alternating procedure for this problem first performs an existential branch to guess a configuration c m that lies halfway along the path from c 1 to c 2 . It then branches universally into two processes: one that recursively tests whether it is possible to get from c 1 to c m in no more than t /2 steps, and a second that performs a test for the transition from c m to c 2 in no more than t /2 steps.

机器S使用这样的递归交替过程来检查初始配置是否可以在2 df ( n )步中达到接受配置。我们选择常数d,以便对于给定的内存约束,M具有不超过 2 个df ( n )配置。

Machine S uses such a recursive alternating procedure to check whether an accepting configuration can be reached from an initial configuration in 2 df ( n ) steps. The constant d is chosen so that M has no more than 2 df ( n ) configurations for a given memory constraint.

交替过程的任何路径上的最大计算时间为O ( f ( n )) 来存储每个递归级别的配置乘以递归深度,即 log 2 df ( n ) = O ( f ( n )) 。因此,该算法以交替时间O ( f 2 ( n ))运行。

The maximum computation time on any path of the alternating procedure is O ( f ( n )) to write the configuration at each recursion level multiplied by the recursion depth, which is log 2 df ( n ) = O ( f ( n )). Thus , this algorithm runs in alternating time O ( f2 ( n )).

引理10.24

Lemma 10.24

对于f ( n ) ≥ log n ,有 ASPACE( f ( n )) TIME(2 O( f ( n )) )。

For f ( n ) ≥ log n we have ASPACE( f ( n )) TIME(2 O( f ( n )) ).

证明我们将构造一个在时间 2 O( f ( n )) 中运行的确定性机器S ,模拟在内存O ( f ( n ))交替机器M。对于输入词w,模拟器Sw构建机器M的计算图。顶点是字w的配置M,最多使用df ( n ) 个磁带单元,其中d是为机器M适当选择的常数因子。我们将边从给定的配置引导到机器M可以一步移动到的那些配置。构建图表后, S浏览它并将某些配置标记为接受。最初,只有接受M台机器的实际配置才会以这种方式标记。如果执行通用分支的配置的所有子配置都标记为接受,则该配置将被标记为接受。如果任何子配置被标记,则存在配置被标记。机器S继续遍历并标记,直到无法根据这些规则标记其他顶点。最后,如果机器Mw的初始配置已被标记为接受,机器S接受。

Proof We construct a deterministic 2-time O( f ( n )) machine S that simulates an alternating machine M that runs in memory O ( f ( n )). For an input word w , the simulator S constructs a graph of computations of M for w . The vertices are configurations of M for word w that use at most df ( n ) tape cells, where d is a constant factor chosen appropriately for M . We draw edges from a given configuration to those configurations that M can transition to in a single step. After constructing the graph, S scans it and marks certain configurations as accepting. Initially, only the actual accepting configurations of M are marked in this way . A configuration that performs a universal branch is marked as accepting if all of its children are so marked. An existential configuration is marked if any of its children are marked. S continues to scan and mark until no additional vertices can be marked according to these rules. Finally, machine S accepts if machine M 's initial configurationfor w was marked as accepting.

w的机器配置数量M是 2 O( f ( n )),因为f ( n ) ≥ log n。因此,配置图的大小也是2 O( f ( n )) ,并且其构建可以在2O ( f ( n ))时间内完成。浏览一遍该图大约需要相同的时间。遍历的总数(即遍历整个图的重复次数)至多等于图中的顶点数,因为在除最后一次之外的每一遍中,至少标记了一个额外的顶点。因此,总运行时间为 2 O( f ( n ))

The number of configurations of the machine M for word w is 2 O( f ( n )) , since f ( n ) ≥ log n . Hence the size of the configuration graph is also 2 O( f ( n )) , and its construction can be done in time 2 O( f ( n )) . A single traversal of the graph takes about the same amount of time. The total number of passes (i.e. iterations of traversing the entire graph) is at most equal to the number of vertices in the graph, since in each pass except the last one at least one additional vertex is marked. Hence the total running time is 2 O( f ( n )) .

引理10.25

Lemma 10.25

对于f ( n ) ≥ log n ,有 ASPACE( f ( n )) Ê TIME(2 O( f ( n )) )。

For f ( n ) ≥ log n we have ASPACE( f ( n )) Ê TIME(2 O( f ( n )) ).

证明我们将展示如何在使用O ( f ( n ) )阶内存的交替图灵机 S 上运行时间为 2 O( f ( n )) 的确定性机器M。这种模拟相当困难,因为机器 S 可用的内存远小于机器M执行的计算的大小在这种情况下,S 只有足够的内存来存储单词w的机器M表的指针,如下图所示。

Proof We show how to simulate a deterministic 2-time Turing machine M that runs in time O( f ( n )) on an alternating Turing machine S that uses memory of order O ( f ( n )). This simulation is quite difficult because the memory available to S is much smaller than the computation size performed by M . In this case, S only has enough memory to store pointers to M 's tableau for a word w , as shown in the figure below.

10.26单词w的M

机器画面

Figure 10.26

Tableau of the M machine for the word w

我们将使用定理 9.30 证明中的配置表示,其中单个符号可以表示机器的状态和磁头下方磁带单元的内容。因此,图 10.26 中单元格d的内容由三个父单元格abc的内容决定。 (左侧或右侧边缘的单元格只有两个前任单元格。)

We will use the same representation of the configuration as in the proof of Theorem 9.30, where a single symbol can represent both the state of the machine and the contents of the tape cell below the head. The contents of cell d in Figure 10.26 are therefore determined by the contents of the three parent cells a , b , and c . (The cells on the left or right edge have only two predecessors.)

模拟机 S 递归地工作,猜测并检查各个表格单元格的内容。为了检查不属于第一行的单元格d的内容,机器 S 存在地猜测父单元格的内容,根据机器M的传递函数检查它们是否产生单元格d的内容,然后执行通用分支递归检查单元格abc的猜测内容。如果d属于第一行,则模拟器直接验证答案,因为它知道机器M的初始配置。我们假设机器M在接受之前将头部移动到最左边的位置,因此机器S可以通过检查表格左下单元格的内容来确定机器M是否接受。所以你可以看到,S 模拟器永远不需要记住多个指向 tableau cell 的指针,因此它的内存消耗是 log 2 O( f ( n )) = O ( f ( n ))。

The simulating machine S operates recursively, guessing and checking the contents of individual tableau cells. To check the contents of cell d that is not in the first row, machine S existentially guesses the contents of the parent cells, checks whether the transition function of machine M implies the contents of cell d , and then performs a universal branch to recursively check the guessed contents of cells a , b , and c . If d were in the first row, the simulator verifies the answer directly, since it knows the initial configuration of machine M . We assume that before accepting, machine M moves its head to the leftmost position, so machine S can determine whether machine M accepts by checking the contents of the bottom-left tableau cell. It is clear that simulator S never needs to remember more than one pointer to a tableau cell, so its memory consumption is log 2 O( f ( n )) = O ( f ( n )).

多项式时间层次结构

Polynomial time hierarchy

交替机器允许您在 PSPACE 类中定义问题的自然层次结构。

Alternating machines allow us to define a natural hierarchy of problems within the PSPACE class.

定义10.27

Definition 10.27

i为自然数。Si-交替图灵机是一种交替图灵机,对于每个输入字和每个计算路径,交错最多i个由连续的通用步骤或连续的存在步骤组成的序列,其中第一序列由通用步骤组成。p i交替图灵机的定义类似,只是第一个序列由通用步骤组成。

Let i be a natural number. An S i -alternating Turing machine is an alternating Turing machine that, for each input word and each computation path, interleaves at most i sequences consisting of consecutive universal steps or consecutive existential steps, where the first sequence consists of universal steps. A P i -alternating Turing machine is defined analogously except that the first sequence consists of universal steps.

我们将Σ i TIME( f ( n ))定义为Σ i交替图灵机在O ( f ( n ))时间内解析的语言类。类似地,我们为P i交替图灵机定义类P i TIME( f ( n )),为内存有限的交替图灵机定义类Σ i SPACE( f ( n ))P i SPACE( f ( n ))机器。我们将多项式时间复杂度层次结构定义为一组类

We define Σ i TIME( f ( n )) as the class of languages ​​that are resolved by Σ i -alternating Turing machines in time O ( f ( n )). Analogously, we define the class P i TIME( f ( n )) for P i -alternating Turing machines and the classes Σ i SPACE( f ( n )) and P i SPACE( f ( n )) for memory-bounded alternating Turing machines. The polynomial-time hierarchy is defined as the set of classes

我们还定义了类 PH = i Σ i P = i P i P。当然,NP = Σ 1 P 和 coNP = P 1 P。此外,我们可以注意到MIN-FORMULA P 2 P。

We also define the class PH = i Σ i P = i P i P. Obviously NP = Σ 1 P and coNP = P 1 P. Additionally, we can note that MIN-FORMULA P 2 P.

10.4

交互式证据系统

10.4

Interactive Evidence Systems

交互式证明系统提供了定义 NP 类的概率等价的能力,其方式类似于概率多项式时间算法等价于 P 类的方式。交互式证明系统的发展对复杂性理论产生了重大影响。在密码学和近似算法领域取得了重要成就。为了更好地理解这个新概念,让我们回顾一下与 NP 类相关的直觉。

Interactive proof systems provide a way to define a probabilistic counterpart to the class NP in much the same way that probabilistic polynomial-time algorithms are to the class P. The development of interactive proof systems has had a significant impact on complexity theory and has led to important advances in cryptography and approximation algorithms. To better understand this new notion, let us recall the intuitions related to the class NP.

属于 NP 类的语言是那些元素配备了可以轻松检查的语言隶属关系短证书的语言。如果有必要,您可以返回第294页查看NP类的定义。现在,我们将尝试通过创建两个新单元来稍微更改此定义的措辞:倡导者(Advocate),负责发现单词属于某种语言的证据;验证者(Verifier),负责检查它。我们可以将倡导者视为试图说服验证者单词w属于语言A的人。我们要求Verifier是一个多项式时间机器;否则他可以自己找到答案。然而,我们不会对专员施加任何计算限制,因为寻找证据可能非常耗时。

Languages ​​in the class NP are those whose members have short language certificates that can be easily checked. If necessary, you can go back to page 294 to refresh your memory on the definition of the class NP. We will now try to reformulate this definition slightly, creating two new entities: the Advocate, who finds proofs that a word belongs to the language, and the Verifier, who checks them. We can think of the Advocate as someone who tries to convince the Verifier that the word w belongs to the language A . We require that the Verifier be a polynomial-time machine; otherwise, it could find the answer on its own. However, we do not impose any computational constraints on the Advocate, since finding proofs can be time-consuming.

例如,考虑SAT问题。监察员可以通过提供满足某个公式Φ的变量估值来让多项式时间验证者相信该公式Φ 是可满足的。监察员能否让同样有限的验证员相信该公式不可满足?目前尚不清楚SAT问题的补集是否属于 NP 类,因此我们不能依赖证书的概念。然而,令人惊讶的是,答案是肯定的,只要我们为监察员和验证员配备两项附加功能即可。首先,他们将能够进行双向对话,交换信息。其次,验证器可以是概率多项式时间机器,以高概率获得正确答案,但不一定具有确定性。这样的监察员和验证员共同构成了一个交互式证据系统。

For example, consider the SAT problem . The Advocate can convince a polynomial-time Verifier that a certain formula Φ is satisfiable by providing a satisfying valuation of the variables. Could the Advocate convince a similarly constrained Verifier that the formula is not satisfiable? It is not known whether the completion of the SAT problem is in NP, so we cannot rely on the concept of certificates. Nevertheless, the answer is, surprisingly, yes , if we equip the Advocate and the Verifier with two additional features. First, they can conduct a two-way dialogue , exchanging information. Second, the Verifier can be a polynomial-time probabilistic machine that arrives at the correct answer with high probability, although not necessarily with certainty. Such an Advocate and Verifier together form an interactive proof system.

图的非同构

Graph non-isomorphism

我们将使用图同构问题的一个优雅示例来演示交互式证明系统的概念。如果图G的顶点可以以与图 H 相同的方式重新编号,则图G和 H 被称为同构。

We will demonstrate the notion of interactive proof systems using the elegant example of the graph isomorphism problem. The graphs G and H are called isomorphic if the vertices of the graph G can be renumbered in such a way that it is identical to the graph H. Let

ISO = { G , H : G和 H 是同构图}。

ISO = { G , H : G and H are isomorphic graphs}.

尽管很明显ISO问题属于 NP 类,但迄今为止,尽管付出了巨大的努力,仍无法识别出在多项式时间内运行的算法或证明该问题是 NP 完备的。它是少数不属于任何这些类别的自然出现的 NP 语言之一。

Although it is clear that the ISO problem is in NP, despite considerable effort, no polynomial-time algorithm has been found for it or it has been shown to be NP-complete. It is one of a small number of naturally occurring NP languages ​​that have not been classified in either category.

在这里,我们将处理一种补充ISO问题的语言- 让我们称之为NONISO = { G , H G和 H 是非同构的图}。目前尚不清楚NONISO是否属于 NP 类,因为我们不知道如何提供证明图不是同构的证书。然而,正如我们稍后将展示的,当两个图不同构时,倡导者可以让验证者相信情况确实如此。

Here we will deal with a language that is the complement of the ISO problem – let us call it NONISO = { G , H : G and H are graphs that are not isomorphic}. It is not known whether NONISO is in the class NP, since we do not know how to produce a certificate showing that the graphs are not isomorphic. Nevertheless, as we will show in a moment, when two graphs are not isomorphic, the Advocate can convince the Verifier that they are.

假设我们有两个图G 1G 2。如果它们是同构的,倡导者可以通过提供适当的同构(对顶点重新编号)来说服验证者。然而,如果这些图不是同构的,那么监察员如何才能让验证者相信情况确实如此呢?我们不要忘记,验证者不必信任监察员,因此监察员仅仅声明缺乏同构是不够的。监察员仍然需要说服验证员。考虑以下简短的协议。

Suppose we have two graphs G 1 and G 2 . If they are isomorphic, then the Advocate could convince the Verifier of this by presenting an appropriate isomorphism (renumbering the vertices). However, if these graphs are not isomorphic, how could the Advocate convince the Verifier that this is the case? Let us not forget that the Verifier does not have to trust the Advocate, so it is not enough for the Advocate to declare that there is no isomorphism. The Advocate also has to convince the Verifier. Consider the following short protocol.

验证者随机选择图G 1G 2,然后对顶点进行随机重新编号,得到图H。然后,它将 H 图表发送给监察员。发言人必须回答图H的来源是图G 1还是G 2。这是协议结束的地方。

The verifier randomly selects a graph G 1 or G 2 , and randomly renumbers the vertices, obtaining a graph H . It then sends the graph H to the Advocate. The Advocate must respond whether the source for H was graph G 1 or G 2 . This concludes the protocol.

如果图G 1G 2确实是非同构的,那么监察员可以始终坚持该协议,因为他可以识别图H是否是图G 1G 2转换的结果。然而,如果这些图是同构的,则H可以由G 1和 G 2产生。因此,即使有无限的计算可能性,专员也有一半的机会获得正确答案。因此,如果倡导者始终给出正确的答案(例如,在协议的 100 次迭代中),那么验证者就有令人信服的证据证明这些图确实是非同构的。

If the graphs G 1 and G 2 are indeed nonisomorphic, then the Advocate can always stick to the protocol, since he can tell whether H is a transformation of G 1 or G 2 . However, if these graphs are isomorphic, then H can arise from either G 1 or  G 2 . Thus, even with unlimited computational power, the Advocate has a 50/50 chance of getting the answer right. So if the Advocate consistently gives the correct answer (say, in 100 iterations of the protocol), then the Verifier has convincing evidence that the graphs are indeed nonisomorphic.

型号定义

Model Definition

为了正式定义交互式证据系统,我们将描述倡导者、验证者以及它们之间的交互。所提供的图非同构问题的例子将会有所帮助。我们将验证者定义为一个函数V,它根据迄今为止交换的消息的历史来计算发送给专员的下一条消息。V函数有三个参数:

To formally define an interactive proof system, we describe the Advocate, the Verifier, and the interaction between them. The example of the graph nonisomorphism problem will be helpful here. We define the Verifier as a function V that computes its next message sent to the Advocate based on the history of messages exchanged so far. The function V has three arguments:

  1. 输入单词。目标是确定该单词是否是某种语言的一部分。在NONISO示例中,输入单词是两个图的编码。
  2. Input word . The goal is to determine whether the word is an element of some language. In the NONISO example , the input word is the encoding of two graphs.
  3. 随机词。为了方便表述定义,我们假设验证者接收到一个随机选择的单词,这相当于赋予了它随机移动的能力。
  4. Random Word . For convenience in formulating the definition, we assume that the Verifier is given a randomly selected word, which is equivalent to endowing it with the ability to make moves randomly.
  5. 交换消息的部分历史记录。该函数无法收集前面提到的消息,因此我们将这些消息的历史记录作为参数传递给它。从m 1m i的消息交换将被写为m 1 # m 2 # # mi
  6. Partial history of exchanged messages . The function has no way to collect previously exchanged messages, so we pass it the history of these messages as an argument. The exchange of messages from m 1 to m i will be written as m 1 # m 2 # # m i .

Verifier 函数的输出要么是该字符串中的下一个m+1消息,要么是接受拒绝消息,指示交互结束。因此,V是以下形式的函数:Σ * × Σ * × Σ * Σ * {接受,拒绝}。

The output of the Verifier function is either the next m i + 1 message in this sequence, or an accept or reject message indicating completion of the interaction. Thus V is a function of the form V : Σ * × Σ * × Σ * Σ * { accept , reject }.

符号V ( w , r , m 1 # ... # m i )= m i +1表示输入单词为w,随机单词为r,当前消息历史记录为m 1m i,并且验证者发送给发言人的下一条消息是m i +1

The notation V ( w , r , m 1 # # m i ) = m i +1 means that the input word is w , the random word is r , the current message history is m 1 to m i , and the next message sent by the Verifier to the Advocate is m i +1 .

监察员是具有无限计算可能性的一方。带有两个参数的函数P :

The Advocate is a party with unlimited computational capabilities. We define it as a function P with two arguments:

  1. 输入单词
  2. Input word
  3. 消息交换的部分历史记录
  4. Partial message exchange history

监察员功能的输出是发送给验证者的另一条消息。形式上,P 是 P 形式的函数:Σ * × Σ * Σ *。

The output of the Advocate function is another message sent to the Verifier. Formally, P is a function of the form P : Σ * × Σ * Σ *.

符号P ( w , m 1 # # mi ) = mi +1表示监察员在m 1mi消息交换后将消息mi +1发送到验证

The notation P ( w , m 1 # # m i ) = m i +1 means that the Ombudsman sends message m i +1 to the Verifier after exchanging messages from m 1 to m i .

我们现在将定义倡导者和验证者之间的交互。对于给定的单词w和 r ,如果对于某些k存在从m 1m k的消息序列,则我们写 ( V P )( w , r ) = Accept

We now define the interaction between the Advocate and the Verifier. For given words w and  r we write ( V P )( w , r ) = accept , if there is a sequence of messages from m 1 to m k for some k , such that

  1. 对于 0 ≤ i < k,其中i是偶数V ( w , r , m 1 # # mi ) = mi +1
  2. for 0 ≤ i < k , where i is an even number, V ( w , r , m 1 # # m i ) = m i +1 ;
  3. 对于 0 < i < k,其中i是奇数,P ( w , m 1 # ... # m i ) = m i +1;并且
  4. for 0 < i < k , where i is an odd number, P ( w , m 1 # # m i ) = m i +1 ;and
  5. m k 历史上的最后一条消息是accept
  6. the last m k message in history is accept .

为了简化 IP 类的定义,我们假设验证器函数的随机输入字的长度以及各方之间交换的每条消息的长度为p ( n ),其中p是仅依赖于验证器的多项式。此外,我们假设交换的消息总数最多为p ( n )。以下定义给出了交互式证据系统接受中的输入词的概率。对于任何长度为n的单词w ,我们定义

To simplify the definition of the IP class, we assume that the length of the random input word to the Verifier function and of each message exchanged between the parties is p ( n ), where p is some polynomial that depends only on the Verifier. Additionally, we assume that the total number of messages exchanged is at most p ( n ). The following definition gives the probability that the interactive proof system accepts an input word w . For any word w of length n, we define

Pr[ V P接受w ] = Pr[( V P )( w , r ) =接受],

Pr[ V P accepts w ] = Pr[( V P )( w , r ) = accept ],

其中r是长度为p ( n )的随机选择的单词。

where r is a randomly chosen word of length p ( n ).

定义10.28

Definition 10.28

我们说语言A属于 IP 类,如果存在一个可在多项式时间内计算的函数V,使得对于某个(任何)函数P和每个(任何)函数以及每个单词w两个条件成立:

We say that a language A belongs to the class IP if there exists a function V computable in polynomial time such that for some (arbitrary) function P and for every (arbitrary) function and for every word w , two conditions hold:

  1. 如果w A,则 Pr[ V P接受w ] ≥ 2/3;
  2. if w A , then Pr[ V P accepts w ] ≥ 2/3;
  3. 如果w A,则 Pr[ V 接受w ] ≤ B
  4. if w A , then Pr[ V accepts w ] ≤ B .

换句话说,如果一个词 ε A中,那么某个 Advocate P(一个“可靠”的 Advocate)将使 Verifier 以很高的概率接受。然而,如果w A,则没​​有发言人(即使是“欺诈性”发言人)将使验证者以高概率接受。

In other words, if a word w A , then some Advocate P (an “honest” Advocate) will cause the Verifier to accept with high probability. However, if w A , then no Advocate (not even a “fraudulent” Advocate ) will cause the Verifier to accept with high probability.

我们可以通过重复试验来增强交互式证明系统的成功概率,如引理 10.5 所示,从而以指数方式降低错误概率。很明显,IP 类同时包含 NP 类和 BPP 类。我们还表明它包含语言NONISO,但不知道它属于这两个类别中的任何一个。正如我们稍后将展示的,IP 类非常大,与 PSPACE 类相同。

We can improve the success probability of an interactive proof system by iterating the trials, as in Lemma 10.5, thus exponentially reducing the error probability. It is clear that the class IP contains the class of both NP and BPP. We have also shown that it includes the language NONISO , which is not known to belong to either class. As we will show in a moment, the class IP is surprisingly large, equal to the class PSPACE.

IP = 空间

IP = PSPACE

在本节中,我们将证明复杂性理论最重要的定理之一:IP 和 PSPACE 类的相等性。由此可见,对于 PSPACE 类中的任何语言,倡导者都可以说服概率多项式时间验证者确定某个单词是否属于该语言,即使传统的成员资格证明是指数级长的。

In this section we prove one of the most significant theorems of complexity theory: the equality of the classes IP and PSPACE. It follows that for any language in the class PSPACE, the Advocate can convince a probabilistic polynomial-time Verifier that a certain word belongs to the language, even if the conventional proof of membership is exponentially long.

定理10.29

Theorem 10.29

IP = P空间。

IP = PSPACE.

我们将定理的证明划分为引理,在每个引理中我们将证明其有效性。第一个引理表明 IP PSPACE。尽管这个证明有些技术性,但它相当于在多项式内存中运行的机器对交互式证明系统的模拟。

We will divide the proof of the theorem into lemmas, in which we show inclusion in every direction. The first lemma shows that IP PSPACE. Although this proof is somewhat technical, it amounts to the simulation of a system of interactive proofs by a polynomial-memory machine.

引理 10.30

Lemma 10.30

IP PSPACE。

IP PSPACE.

证明 A是属于 IP 类的语言。假设语言 A 的验证器V准确列出了长度为n的输入字w的p = p ( n ) 条消息。我们将构建一个PSPACE类机器来模拟V的操作我们定义的任何单词

Proof Let A be a language of class IP. Assume that a verifier V for a language A lists exactly p = p ( n ) messages for an input word w of length n . We construct a machine of class PSPACE that simulates the operation of V . For any word w , we define

Pr[ V接受 w] = max P Pr[ V P接受w ]。

Pr[ V accepts w] = max P Pr[ V P accepts w ].

如果单词w属于语言A ,则该值至少为 2/3 ;如果不属于语言,则该值最多为B。我们将向您展示如何在多项式时间内计算该值。令M j表示消息历史m 1 # # m j。我们将通过添加任何初始消息序列M j来概括VP之间交互的定义。如果我们可以用消息m j +1将序列M j扩展到m p ,我们将写 ( V P )( w , r , M j ) = Accept ,这样

This value is at least 2/3 if the word w belongs to language A , or at most B , if it does not. We will show how to compute this value in polynomial time. Let M j denote the history of messages m 1 # # m j . We generalize the definition of the interaction between V and P by adding to it an arbitrary initial sequence of messages M j . We will write ( V P )( w , r , M j ) = accept , if we can extend the sequence M j with messages m j +1 to m p , such that

  1. 对于 0 ≤ i < p,其中i是偶数V ( w , r , m 1 # # mi ) = mi +1
  2. for 0 ≤ i < p , where i is an even number, V ( w , r , m 1 # # m i ) = m i +1 ;
  3. 对于 0 < i < p,其中i是奇数,P ( w , m 1 # ... # m i ) = m i +1;并且
  4. for 0 < i < p , where i is an odd number, P ( w , m 1 # # m i ) = m i +1 ;and
  5. m p 的最后一条消息是Accept
  6. the last m p message in history is accept .

请注意,这些条件要求V生成的消息与M j中已存储的消息匹配。进一步扩展前面的定义,我们定义

Note that these conditions require that the messages generated by V be consistent with those already recorded in the sequence M j . Extending the earlier definitions further, we define

Pr[ V P接受w,从序列M j ] = Pr r [( V P )( w , r , M j ) = Accept ]。

Pr[ V P accepts w , starting from the sequence M j ] = Pr r [( V P )( w , r , M j ) = accept ].

此时以及该证明的其余部分,符号 Pr r表示为与初始交互序列M j匹配的所有单词r计算的概率。如果这样的r不存在,我们假设概率为 0。然后我们定义

At this point and for the rest of this proof, the notation Pr r denotes the probability computed for all words r that are consistent with the initial interaction sequence M j . If no such r exists, we take the probability to be 0. Then we define

Pr[ V接受单词w,从序列M j开始] = max P Pr[ V P接受单词w,从序列M j开始]。

Pr[ V accepts word w , starting from the sequence M j ] = max P Pr[ V P accepts word w , starting from the sequence M j ].

对于每个 0 ≤ jp和每个消息序列M j ,我们从初始情况j = p开始,归纳定义N M j来减少j。对于包含p条消息的消息字符串M p,如果字符串M p与V为某个单词r生成的消息匹配并且mp = Accept 则令N M p = 1 。否则,令 N M p = 0。

For each 0 ≤ jp and each message sequence M j we define N M j inductively for decreasing j , starting from the initial case j = p . For a message sequence M p containing p messages, let N M p = 1 if the sequence M p is consistent with the messages generated by V for some word r and m p = accept . Otherwise let N M p = 0.

对于j < p和消息序列M j,我们定义N M j如下:

For j < p and a message sequence M j we define N M j as follows:

这里,符号 wt-avg mj +1 N M j +1表示表达式Σ mj +1 (Pr r [ V ( w , r , M j ) = m j +1N M j +1。该表达式是由验证者发送消息m j +1的概率加权的值N M j +1的平均值。

Here the notation wt-avg mj +1 N M j +1 denotes the expression Σ mj +1 (Pr r [ V ( w , r , M j ) = m j +1 ] N M j +1 . This expression is the average of the values ​​of N M j +1 weighted by the probability that the Verifier will send message m j +1 .

M 0为空消息字符串。我们将提出关于N M0值的两个观察结果。首先,我们可以计算多项式存储器中N M0的值。我们将通过对每个jM j计算N M j递归地获得它。计算 max mj +1很简单。为了计算 wt-avg mj +1,我们查看长度为p的所有单词r并消除那些会导致验证器返回与字符串M j不匹配的消息的单词。如果没有剩余单词r,则 wt-avg mj +1为 0。如果剩余一些单词,我们计算其中的多少部分将导致验证者生成消息m j +1。然后,我们将N M j +1的值乘以该分数来计算平均值。递归深度为p,因此多项式内存就足够了。

Let M 0 be the empty message sequence. We make two observations about the value of N M 0 . First, we can compute the value of N M 0 in polynomial memory. We obtain it recursively by computing N M j for each j and M j . Computing max m j +1 is straightforward. To compute wt-avg m j +1 , we scan through all the words r of length p and eliminate any that would cause the verifier to return a message that is inconsistent with the sequence M j . If there are no words r left , then wt-avg m j +1 is 0. If there are some words left, we compute what fraction of them will cause the verifier to generate message m j +1 . We then multiply the value of N M j +1 by this fraction to compute the average. The recursion depth is p , and thus polynomial memory suffices.

其次,N M0等于 Pr[ V接受单词w ],该值是确定单词w是否属于语言A所需的值。我们将通过归纳法证明后一个命题。

Second, N M0 is equal to Pr[ V accepts word w ], the value needed to determine whether word w belongs to language A . We will prove the latter statement by induction.

声明 10.31

Statement 10.31

对于每个 0 ≤ jp和每个M j

For every 0 ≤ jp and for every M j ,

N M j = Pr[ V接受从字符串M j开始的单词w ]。

N M j = Pr[ V accepts a word w , starting from the sequence M j ].

我们通过对j进行归纳来证明这个命题,归纳基础是j = p 的情况,之后j的值减小到零。

We will prove this statement by induction on j , with the inductive basis being the case j = p , after which the value of j is reduced to zero.

基本步骤:我们将证明该论文对于j = p成立。我们知道消息m p要么是接受,要么是拒绝。如果m p接受,根据定义,N M p的值为 1,并且 Pr[ V接受单词w,从字符串M j开始] = 1,因为消息字符串已经包含一个接受,因此该语句为 true 。消息m p拒绝时的情况类似。

Basic step: We show that the thesis holds for j = p . We know that the message m p is either accept or reject . If m p then accept , N M p is by definition 1, and Pr[ V accepts word w , starting from the sequence M j ] = 1, since the sequence of messages already contains an accept, so the statement is true. The case when the message m p is reject is analogous.

归纳步骤:我们假设该论题对于某些j +1 ≤ p和任何消息序列M j +1成立。我们将证明它对于j和任何消息序列M j都是满足的。如果j是偶数,则m j +1是从V到 P的消息。然后我们得到一个相等的序列:

Inductive step: We assume that the thesis holds for some j +1 ≤ p and any sequence of messages M j +1 . We will show that it holds for j and any sequence of messages M j . If j is even, m j +1 is a message from V to P. We then obtain the sequence of equalities:

等式 1 是N M j的定义。等式 2 由归纳假设得出。等式 3 由概率 Pr[ V接受单词w,从序列M j开始]的定义得出。因此,我们看到当j为偶数时,命题成立。如果j是奇数,则消息m j +1P转发V。然后我们有另一个等式序列:

Equality 1 is the definition of N M j . Equality 2 follows from the inductive assumption. Equality 3 follows from the definition of probability Pr[ V accepts a word w , starting from the sequence M j ]. We therefore see that the thesis is satisfied when j is even. If j is odd, the message m j +1 is passed from P to V . We then have another sequence of equalities:

等式 1 是N M j的定义。等式 2 由归纳假设得出。我们将等式3分为两个不等式。出现不等式 ≤ 是因为监察员在最大化底行的约束的同时,可以发送消息m j +1最大化顶行的值。不平等≥的发生是因为同一个监察员无法比发送相同的消息做得更好。除了最大化顶行的消息之外,发送任何其他内容都会减少结果值。这样就完成了j奇值的证明,从而完成了定理 10.29 的单向证明。

Equality 1 is the definition of N M j . Equality 2 follows from the inductive assumption. Equality 3 is divided into two inequalities. The inequality ≤ holds because the Advocate, by maximizing the constraint in the bottom row, could have sent a message m j + 1 maximizing the value in the top row. The inequality ≥ holds because the same Advocate could do no better than sending the same message. Sending anything other than a message maximizing the top row would reduce the resulting value. This completes the proof for odd values ​​of j , and thus the proof of Theorem 10.29 in one direction.

现在我们将证明反过来也是正确的。在下面所示的引理证明中,我们引入了一种用于分析计算的新颖代数技术。

We now show that the theorem is true in the other direction. In the proof of the lemma given below, we introduce a novel algebraic technique for analyzing computations.

引理 10.32

Lemma 10.32

PSPACE IP。

PSPACE IP.

在继续证明这个引理之前,我们先证明一个较弱的结果来说明所使用的技术。让我们将逻辑公式可满足性问题的计数问题定义为一种语言

Before we proceed to the proof of this lemma, we prove a weaker result that illustrates the technique used. Let us define the counting problem for the satisfiability problem of a logical formula as the language

#SAT = { 〈Φ , k : Φ是 CNF 形式的公式,其中k恰好满足变量估值}。

#SAT = { 〈Φ , k : Φ is a CNF formula with exactly k satisfying valuations of variables}.

定理10.33

Theorem 10.33

#SAT ® IP。

#SAT IP.

证明概念 该证明显示了一个协议,其中监察员让验证者相信k是给定 CNF 公式Φ的满足赋值的实际数量。在继续讨论协议本身之前,我们考虑另一个协议,它具有一些正确性特征,但还不够,因为它需要指数时间验证器。让我们假设公式Φ包含从x 1x m的变量。

The Concept of the Proof This proof shows a protocol in which the Advocate convinces the Verifier that k is the actual number of satisfying value assignments for a given CNF formula Φ . Before we turn to the protocol itself, we consider another protocol that has some correctness properties but is insufficient because it requires an exponential-time Verifier. Assume that the formula Φ contains variables from x 1 to x m ​​.

f i为函数,其中对于 0 ≤ im且对于a 1 , …, a i {0, 1},我们将f i ( a 1 , …, a i ) 定义为此类满足评估的数量公式Φ,其中x j = a jji。常数函数f 0 ()是公式Φ的满足评估的数量。如果a的这些值满足公式Φ,则函数f m ( a 1 , …, a m ) 等于 1 ;否则其值为 0。 对于所有i < ma 1 , …, a i,有一个简单的恒等式需要证明:

Let f i be a function, where for 0 ≤ im and for a 1 , …, a i {0, 1} we define f i ( a 1 , …, a i ) as the number of such satisfying valuations of the formula Φ , for which x j = a j for ji . The constant function f 0 () is the number of satisfying valuations of the formula Φ . The function f m ( a 1 , …, a m ) is equal to 1 if these values ​​of a i satisfy the formula Φ ; otherwise it has the value 0. An easy-to-prove identity holds for all i < m and a 1 , …, a i :

f i ( a 1 , …, a i ) = f i +1 ( a 1 , …, a i , 0) + f i +1 ( a 1 , …, a i , 1)。

f i ( a 1 , …, a i ) = f i +1 ( a 1 , …, a i , 0) + f i +1 ( a 1 , …, a i , 1).

#SAT语言的协议从阶段 0 开始,到阶段m + 1结束。输入单词是〈Φ , k 对。

The protocol for the #SAT language starts with phase 0 and ends with phase m + 1. The input word is a pair 〈Φ , k .

阶段 0P将f 0 ()发送给V。

Phase 0 . P sends f 0 () to V .

V检查是否k = f 0 (),如果不是则拒绝。

V checks if k = f 0 () and rejects if it is not the case.

阶段1P将f 1 (0) 和f 1 (1)发送给V。

Phase 1. P sends f 1 ( 0) and f 1 (1) to V.

V检查是否f 0 () = f 1 (0) + f 1 (1),如果不是则拒绝。

V checks if f 0 () = f 1 (0) + f 1 (1) and rejects if it is not the case.

阶段2P将f 2 (0.0)、f 2 (0.1)、f 2 (1.0) 和f 2 (1.1)发送给V。

Phase 2. P sends to V f 2 (0,0), f 2 (0,1), f 2 (1,0) and f 2 (1,1).

V检查 f 1 (0) = f 2 (0,0)+ f 2 (0,1) 和f 1 (1) = f 2 (1,0)+ f 2 (1,1) 并拒绝,如果不是这种情况。

V checks if f 1 (0) = f 2 (0,0)+ f 2 (0,1) and f 1 (1) = f 2 (1,0)+ f 2 (1,1) and rejects if this is not the case.

...

...

相 mP为变量a的每次评估发送f m ( a 1 , …, a m ) 。

Phase m . P ​​sends f m ( a 1 , …, a m ) for each valuation of variables a i .

V检查将函数f m -1与函数f m关联的 2 m -1个等式,如果有不满足则拒绝。

V checks 2m −1 equalities relating the function f m −1 to the function f m and rejects if any of them is not satisfied.

m+1 相V检查变量a的每次评估的f m ( a 1 , …, a m )值是否正确,并通过计算每次评估的公式Φ的值。如果所有评估均正确,V接受;否则V拒绝。这样就完成了协议的描述。

Phase m+1 . V checks whether the values ​​f m ( a 1 , …, a m ) are valid for each valuation of variables a i , by computing the value of the formula Φ for each valuation. If all valuations are valid, V accepts ; otherwise, V rejects . This completes the description of the protocol.

该协议并不构成#SAT属于IP类的证据,因为验证者需要指数时间来读取专员发送的指数长消息。但让我们检查一下它的有效性,因为它将帮助我们理解下一个更有效的协议。

This protocol does not prove that #SAT belongs to the IP class, because the Verifier needs exponential time just to read the exponentially long messages sent by the Advocate. However, let's examine its correctness, because it will help us understand the next, more efficient protocol.

直观上,我们可以说,如果倡导者可以让验证者相信该单词属于语言A ,则该协议可以解析语言A。换句话说,如果一个词是一个语言元素A,某个拥护者就能以很高的概率使Verifier接受。如果该单词不是语言的一部分,则任何倡导者(无论多么不诚实或狡猾)都无法使验证者以较低的概率接受它。我们使用符号P来表示严格遵守协议的发言人,因此如果某个单词属于语言A,那么V将有很高的概率接受该单词。我们使用符号来表示当输入单词不属于语言A时与验证者交换消息的任何发言人。我们可以将视为对手,因为它试图在V应拒绝时让V接受。条款应与“不诚实”监察员一词相关联。

Intuitively, we can say that this protocol resolves language A , if the Advocate can convince the Verifier that the word belongs to language A . In other words, if the word is an element of language A , some Advocate can cause the Verifier to accept with high probability. If the word does not belong to the language, no Advocate—not even a dishonest or devious one—can cause the Verifier to accept it with more than low probability. We use the symbol P to denote an Advocate who strictly adheres to the protocol and thus will cause V to accept the word with high probability if it belongs to language A . We use the symbol to denote any Advocate who exchanges messages with the Verifier when the input word does not belong to language A . We can think of as an adversary, since he tries to persuade V to accept when V should reject. The notation should bring to mind the notation of a “dishonest” Advocate.

在刚刚描述的#SAT语言的协议中,验证器忽略其随机输入单词并确定性地工作。为了证明协议的正确性,我们将建立两个事实。首先,如果k是公式Φ满足评估的正确数量,则存在某个倡导者P将使V接受。这位监察员在每个阶段都给出了正确答案。其次,如果k不合适,任何倡导者都会导致V拒绝。我们可以如下证明这一点。

In the protocol for the #SAT language described just now, the verifier ignores its random input word and acts deterministically. To prove the correctness of the protocol, we establish two facts. First, if k is the correct number of satisfying valuations of the formula Φ , then there is some Advocate P that will cause V to accept. Such an Advocate gives the correct answers in each phase. Second, if k is not correct, any Advocate will cause V to reject. We can justify this as follows.

如果k不正确并且给出了正确的答案,V将在阶段 0 立即拒绝,因为f 0 () 是公式Φ的满足赋值的数量,因此f 0 () k。为了使V在阶段 0 中不被拒绝,P̃必须为f 0 ()发送一个无效值,我们将其写为0 ()。直观上,我们可以说0 ()是对f 0 ()值的欺骗。就像在生活中一样,谎言会引发更多的谎言,被迫对f i的后续值撒谎,以避免在后期阶段检测到欺骗行为。然而,最终这些谎言被揭露,当V直接检查函数f m的值时, P̃在阶段m + 1中被揭露。

If k is not correct and gives correct answers, V will reject immediately in phase 0, since f 0 () is the number of satisfying assignments of the formula Φ , so f 0 () k . In order for V not to reject in phase 0, must send an incorrect value for f 0 (), which we will write as 0 (). Intuitively, we can say that 0 () is a deception about the value of f 0 (). As in life, lying entails further lies and is forced to lie about the subsequent values ​​of f i , to avoid detection of the deception in later phases. Eventually, however, these lies come to light and is exposed in phase m + 1, when V directly checks the values ​​of the function f m .

更具体地说,由于0 () f 0 (),因此在第 1 阶段发送的值f 1 (0) 和f 1 (1) 中至少有一个必须是无效的,否则V在检查后会拒绝f 0 () = f 1 (0) + f 1 (1)。我们假设f 1 (0) 是假值,并将其称为1 (0)。继续这个推理,我们看到在每个阶段必须发送一些虚假值i ( a 1 , …, a i ),否则V将在该阶段拒绝。然而,当V在m + 1阶段检查m ( a 1 , …, a m ) 的假值时,它无论如何都会拒绝。所以我们已经证明,如果k是一个无效数,那么无论P̃做什么, V都会拒绝。所以协议是正确的。

More precisely, since 0 () f 0 (), at least one of the values ​​f 1 (0) and f 1 (1) sent by in phase 1 must be invalid, since otherwise V would reject after checking that f 0 () = f 1 (0) + f 1 (1). Let us assume that this f 1 (0) is the invalid value and call it 1 (0). Continuing this reasoning, we see that in each phase must send some invalid value i ( a 1 , …, a i ), or V would reject at that stage. However, when V checks for an invalid value m ( a 1 , …, a m ) in phase m + 1, it will reject anyway. So we have shown that if k is an invalid number, then V will reject no matter what does . So the protocol is correct.

该协议的问题在于每个阶段的消息数量都会加倍。发生这种加倍的原因是验证器需要两个值f i +1 (..., 0) 和f i +1 (..., 1) 来确认一个值f i (..., . .)。如果我们能找到一种仅使用f i +1的一个值来检查f i值的方法,那么消息数量根本不会增加。我们可以通过将函数f i扩展到非逻辑参数并检查从有限域中随机选择的某个z的单个值f i +1 (..., z )来实现这一点。

The problem with this protocol is that the number of messages doubles in each phase. This doubling occurs because the Verifier needs two values ​​f i +1 (…, 0) and f i +1 (…, 1) to verify a single value f i (. . .). If we could find a way to check the value of f i using only a single value f i +1 , the number of messages would not increase at all. We can achieve this by extending the functions f i to non-logical arguments and checking a single value f i +1 (…, z ) for some z chosen at random from the finite field.

证明 Φ为 CNF 形式的公式,包含变量x 1 , …, x m。在一种称为算术化的技术中我们将公式Φ与多项式p ( x 1 , …, x m ) 相关联,通过模拟逻辑运算Ø与算术运算 + 和 × 来模拟公式Φ,如下所示。如果α和β是子公式,我们可以替换表达式

Proof Let Φ be a CNF formula with variables x 1 , …, x m . In a technique called arithmetization, we associate the formula Φ with a polynomial p ( x 1 , …, x m ), which mimics the formula Φ by simulating the logical operations , , and ¬ with the arithmetic operations + and × in the following way. If α and β are subformulas, we can replace the expressions

α∧βαβ,

α β by αβ,

Ø α 大于 1 – α,

Ø α by 1 – α,

α β 由 α * β = 1 – (1 – α)(1 – β)。

α β by α * β = 1 – (1 – α)(1 – β).

我们可以注意到,任何多项式变量p的次数都不大,这一点稍后会很重要。运算 αβ 和 α * β 给出一个多项式,其次数最多为表示 α 和 β 的多项式的次数之和。由此可见,任何变量的阶数最多为n,其中n是公式Φ的长度。

We can note, and this will be important later, that the degree of any polynomial variable p is not large. The operations αβ and α * β give a polynomial whose degree is at most the sum of the degrees of the polynomials representing α and β. It follows that the degree of any variable is at most n , where n is the length of the formula Φ .

如果我们将逻辑值分配给多项式p的变量,我们将获得与此分配的公式Φ相同的值。当变量没有分配逻辑值时计算多项式p ,对于公式Φ没有明显的解释。尽管如此,证明还是使用这样的赋值来分析公式Φ,类似于定理 10.13 的证明,其中我们使用非布尔替换来分析分支程序。我们将从具有q 个元素的有限域F中选择变量的值,其中q至少为2n

If we assign Boolean values ​​to the variables of the polynomial p , we get the same value as for the formula Φ for this assignment. Evaluating the polynomial p when the variables are not assigned Boolean values ​​has no obvious interpretation for the formula Φ . Nevertheless, the proof uses such assignments to analyze the formula Φ , similarly to the proof of Theorem 10.13, in which we used non-Boolean substitutions to analyze programs with branches. We will choose the values ​​of the variables from a finite field F with q elements, where q is at least 2n .

我们将使用多项式p重新定义我们在证明概念中展示的函数f i 。对于 0 ≤ im且对于a 1 , …, a i F,令

We will use the polynomial p to redefine the function f i , which we showed in the proof concept. For 0 ≤ im and for a 1 , …, a i F , let

请注意,此更改扩展了原始定义,因为当我们将 1 的逻辑值替换为 i两种公式兼容的。因此,f 0 () 仍然是满足公式Φ的赋值的数量。每个函数f i ( x 1 , …, x i ) 现在可以表示为从x 1x i 的变量的多项式。这些多项式的次数最多等于多项式p的次数。

Note that this change extends the original definition, since both formulations are consistent when we substitute logical values ​​into a 1 for a i . Thus, f 0 () is still the number of satisfying assignments of the formula Φ . Each of the functions f i ( x 1 , …, x i ) can now be represented as a polynomial in the variables x 1 to x i . The degree of each of these polynomials is at most equal to the degree of p .

我们现在将介绍#SAT语言的协议。首先,验证器V接收输入词〈Φ , k 并对公式Φ进行算术运算以获得多项式p。这些操作在具有q 个元素的域F中执行,其中q是大于2n 的质数。 (找到这样一个素数q需要一个额外的步骤,但我们在这里跳过它,因为更强的定理 IP = PSPACE 的证明不需要它。)我们在每个阶段的描述开头都在双方括号中添加了注释。

We now present a protocol for the language #SAT . First, the verifier V receives an input word 〈Φ , k and arithmeticizes a formula Φ to obtain a polynomial p . The operations are performed on a field F with q elements, where q is a prime number greater than 2 n . (Finding such a prime q requires an additional step, but we omit it here, since the proof of the stronger theorem, IP = PSPACE, does not require it.) At the beginning of the description of each phase, we place comments in double square brackets.

阶段 01P发送f 0 ()。1

Phase 0 . P transmits f 0 ().

P V:P 将f 0 () 发送到V

P V : P sends f 0 () to V .

V检查是否k = f 0 ()。如果不是,则V 丢弃

V checks if k = f 0 (). If not, V rejects .

阶段11P使V相信,如果f 1 ( r 1 ) 正确,则值f 0 () 正确。1

Phase 1. P convinces V that the value f 0 () is correct if f 1 ( r 1 ) is correct.

P VP输出系数f 1 ( z ),表示为变量z的多项式。

P V : P sends the coefficients of f 1 ( z ) represented as a polynomial in the variable z .

V使用这些系数来计算f 1 (0) 和f 1 (1)。

V uses these coefficients to calculate f 1 (0) and f 1 (1).

V检查是否f 0 () = f 1 (0) + f 1 (1),如果不是则拒绝。

V checks if f 0 () = f 1 (0) + f 1 (1) and rejects if it is not the case.

(回想一下,所有计算都在字段F中。)

(Recall that all computations are in the field F .)

V PVF中选择一个随机值r 1并将其发送给P。

V P : V randomly selects a value r 1 from the field F and passes it to P .

阶段21P使V相信,如果f 2 ( r 1 , r 2 ) 正确,则f 1 ( r 1 )的值是正确的。1

Phase 2. P convinces V that the value f 1 ( r 1 ) is correct if f 2 ( r 1 , r 2 ) is correct.

P VP发送系数f 2 ( r 1 , z ),表示为变量z的多项式。

P V : P outputs the coefficients of f 2 ( r 1 , z ) represented as a polynomial in the variable z .

V使用这些系数来计算f 2 ( r 1 , 0) 和f 2 ( r 1 , 1)。

V uses these coefficients to calculate f 2 ( r 1 , 0) and f 2 ( r 1 , 1).

V检查是否f 1 ( r 1 ) = f 2 ( r 1 , 0) + f 2 ( r 1 , 1) ,如果不是这种情况则拒绝。

V checks if f 1 ( r 1 ) = f 2 ( r 1 , 0) + f 2 ( r 1 , 1) and rejects if it is not the case.

V PVF中随机选择值r 2并将其发送给P。

V P : V randomly selects a value r 2 from the field F and passes it to P .

...

...

第一阶段1P使V确信,如果f i ( r 1 , …, r i ) 正确,则值f i −1 ( r 1 , …, r i −1 ) 是正确的。1

Phase i . P convinces V that the value f i −1 ( r 1 , …, r i −1 ) is correct if f i ( r 1 , …, r i ) is correct.

P VP输出系数f( r 1 , …, r i -1 , z ) ,表示为变量z的多项式。

P V : P outputs the coefficients f i ( r 1 , …, r i −1 , z ) represented as a polynomial in the variable z .

V使用这些系数来计算f i ( r 1 , …, r i −1 , 0) 和f i ( r 1 , …, r i −1 , 0) 。

V uses these coefficients to calculate f i ( r 1 , …, r i −1 , 0) and f i ( r 1 , …, r i −1 , 0).

V检查f i −1 ( r 1 , …, r i −1 ) = f i ( r 1 , …, r i −1 , 0) + f i ( r 1 , …, r i −1 , 0 )如果不是则拒绝

V checks if f i -1 ( r 1 , …, r i −1 ) = f i ( r 1 , …, r i −1 , 0) + f i ( r 1 , …, r i −1 , 0) and rejects if it is not the case.

V PVF中选择一个随机值r i并将其发送给P。

V P : V randomly selects a value r i from the field F and passes it to P .

...

...

m+1 相1V直接检查f m ( r 1 , …, r m )的值是否正确。1

Phase m+1 . V directly checks whether the value of f m ( r 1 , …, r m ) is correct.

V计算p ( r 1 , …, r m )的值,并将其与为f m ( r 1 , …, r m )获得的值进行比较。如果这些值相等,则接受;否则它会拒绝

V computes the value of p ( r 1 , …, r m ) to compare it with the value it obtained for f m ( r 1 , …, r m ). If these values ​​are equal, it accepts ; otherwise, it rejects .

协议的描述到此结束。

This concludes the description of the protocol.

我们现在将展示该协议解析#SAT语言。首先,如果公式Φk 个满足的赋值,只要 Advocate P 遵循协议,V就一定会接受。其次,我们将证明,如果公式Φ没有恰好k 个令人满意的分配,那么没有一个倡导者能够以比某个小值更大的概率导致接受。令为任意倡导者。

We now show that this protocol is resolved by the language #SAT . First, if a formula Φ has k satisfying assignments, V will definitely accept, provided that Advocate P follows the protocol. Second, we show that if a formula Φ does not have exactly k satisfying assignments, then no Advocate can cause acceptance with greater probability than some small value. Let be any Advocate.

为了防止V从一开始就拒绝,必须在阶段 0 中发送错误值0 () 而不是f 0 ()。因此,在阶段 1 中,Vf 1 () 计算的值之一( 0) 和f 1 ( 1) 一定是不正确的。因此, 为函数f 1 ( z ) 作为变量z的多项式输出的系数必定是不正确的。令1 ( z ) 为由传输系数表示的函数。现在到了关键的证明步骤。

To prevent V from being rejected at the very beginning, must send an incorrect value 0 () instead of f 0 () in phase 0. For this reason, in phase 1 one of the values ​​that V computes for f 1 (0) and f 1 (1) must be incorrect. Thus, the coefficients that sends for the function f 1 ( z ) as a polynomial in z must be incorrect. Let 1 ( z ) be the function represented by the sent coefficients. Now comes the crucial step of the proof.

V从域F中选择一个随机值r 1时,我们可以得出结论1 ( r 1 )不太可能等于f 1 ( r 1 )。对于n ≥ 10 我们将证明

When V chooses a random value r 1 from the field F , we can conclude that it is unlikely that 1 ( r 1 ) is equal to f 1 ( r 1 ). For n ≥ 10 we will show that

Pr[ 1 ( r 1 ) = f 1 ( r 1 )]< n −2

Pr[ 1 ( r 1 ) = f 1 ( r 1 )]< n −2 .

该概率约束源自引理 10.14。次数最多为d的一个变量的多项式不能有超过d 个根,除非它始终等于 0。因此,次数不大于d的一个变量的任意两个多项式最多可以在d处相等,除非它们在每个位置都相等place ,即它们是相同的。

This probability bound follows from Lemma 10.14. A polynomial in one variable of degree at most d cannot have more than d roots unless it is always equal to 0. Hence any two polynomials in one variable of degree at most d can be equal in at most d places unless they are equal in every place, i.e. they are identical.

回想一下,函数f̃ 1的多项式的次数最多为n,并且如果作为函数1提交的多项式的次数大于n ,则V会拒绝。我们已经确定这些函数不相同,因此从引理 10.14 可以得出,它们最多在n 个位置上可以相等。本体F的尺寸大于2n。因此, r 1成为这些函数相等的位置之一的概率至多为n /2 n ,当n ≥ 10时,该概率小于n −2 。

Recall that the degree of the polynomial for the function f 1 is at most n , and that V rejects if the degree of the polynomial sent by as a function of f̃ 1 is greater than n . We have already established that these functions are not identical, so Lemma 10.14 implies that they can be equal in at most n places. The size of the field F is greater than 2n . The probability that r 1 turns out to be one of the places where these functions are equal is therefore at most n /2n , which is less than n −2 for n ≥ 10.

总结到目前为止我们所展示的内容,如果0 () 的值是错误的,那么函数1的多项式也一定是错误的,然后1 ( r 1 )的值很可能是错误的:凭借之前的观察。万一1 ( r 1 ) 等于f 1 ( r 1 ),这意味着倡导者在此阶段“幸运”,仍然有机会让V接受(尽管V应该拒绝) ,遵循协议后面P的说明。

To summarize what we have shown so far, if the value 0 () is wrong, then the polynomial for the function 1 ( r 1) must also be wrong, and then the value 1 ( r 1 ) will most likely be wrong by the previous observation. In the unlikely case that 1 ( r 1 ) is equal to f 1 ( r 1 ), however, this means that Advocate was "lucky" in this phase and still has a chance to get V to accept (although V should reject) by following the instructions for P later in the protocol.

继续这个论证,如果f̃ 1 ( r 1 )的值是错误的,那么V在第 2 阶段计算的值f 2 ( r 1 , 0) 和f 2 ( r 1 , 1)中至少有一个必须是也是错误的,因此, 为变量z的多项式f 2 ( r 1 , z )发送的系数一定是错误的。令2 ( r 1 , z ) 为系数已被转移的函数。多项式f 2 ( r 1z ) 和2 ( r 1z ) 的次数最多为n。因此,如前所述,对于来自场F的r 2随机值,它们相等的概率至多为n -2。因此,如果V随机选择r 2的值,则2 ( r 1 , r 2 )的值很有可能是不正确的。

Continuing this argument, if the value 1 ( r 1 ) was wrong, then at least one of the values ​​f 2 ( r 1 , 0) and f 2 ( r 1 , 1) that V computes in phase 2 must also be wrong, so the coefficients sent by for the polynomial f 2 ( r 1 , z ) in variable z must be wrong. Let 2 ( r 1 , z ) be the function whose coefficients were sent. The polynomials f 2 ( r 1z ) and 2 ( r 1z ) have degree at most n . Thus, as before, the probability that they are equal for a random value r 2 from the field F is at most n −2 . Thus, if V randomly chooses a value r 2 , the value 2 ( r 1 , r 2 ) will be wrong with high probability.

在一般情况下类似地进行,我们可以证明对于每个 1 ≤  ≤  m,如果

Proceeding analogously in the general case, we can show that for every 1 ≤  ≤  m , if

i −1 ( r 1 , …, r i −1 ) f i −1 ( r 1 , …, r i −1 ),

i −1 ( r 1 , …, r i −1 ) f i −1 ( r 1 , …, r i −1 ),

然后对于n ≥ 10 且对于从字段F中随机选择的r i

then for n ≥ 10 and for r i chosen randomly from the field F ,

Pr[ i −1 ( r 1 , …, r i −1 ) = f i −1 ( r 1 , …, r i −1 )] ≤ n −2

Pr[ i −1 ( r 1 , …, r i −1 ) = f i −1 ( r 1 , …, r i −1 )] ≤ n −2 .

如您所见,通过为f 0 () 赋予无效值,被迫为f 1 ( r 1 )、f 2 ( r 1 , r 2 ) 等赋予无效值f m ( r 1 , …, r m )。倡导者很幸运并且V选择r i 的概率,使得i ( r 1 , …, r i ) = fi ( r 1 , …, r i ) 即使ifi不同在某个相中,最多等于相数m乘以n –2,即最多 1/ n。如果P̃幸运的话,它最终会传输错误的f m ( r 1 , …, r m )值。但是,它会在m + 1 阶段直接检查V 的值,并会捕获此时的任何错误。因此,如果k不是公式Φ的满足分配的数量,则没有 Advocate 可以使 Verifier 以大于 1/ n的概率接受。

As we can see, by providing an incorrect value for f 0 ( ), is forced to provide incorrect values ​​for f 1 ( r 1 ), f 2 ( r 1 , r 2 ), and so on up to f m ( r 1 , …, r m ). The probability that Advocate will be lucky and that V will choose r i such that i ( r 1 , …, r i ) = f i ( r 1 , …, r i ), even though i and f i are different in some phase, is at most equal to the number of phases m multiplied by n –2 , which is at most 1/ n . If is lucky, it will eventually provide an incorrect value for f m ( r 1 , …, r m ). However, V checks this value directly in phase m + 1 and catches any error at that point. Therefore, if k is not the number of satisfying assignments of the formula Φ , no Advocate can cause the Verifier to accept with probability greater than 1/ n .

为了完成定理的证明,我们应该证明Verifier是一个在多项式时间内运行的概率算法,但这从它的描述中是显而易见的。

To complete the proof of the theorem, we should show that the Verifier is a probabilistic algorithm running in polynomial time, but this is obvious from its description.

我们现在可以回到引理 10.32 的证明,指出 PSPACE IP。该证明类似于定理 10.33 的证明,只是我们将使用另一种方法来降低协议中出现的多项式的次数。

We can now return to the proof of Lemma 10.32, which states that PSPACE IP. The proof is analogous to the proof of Theorem 10.33, except that we use an additional way of reducing the degrees of the polynomials in the protocol.

证明的概念 让我们首先尝试使用前面证明中使用的想法并确定困难出现在哪里。为了证明PSPACE类中的每种语言都属于IP类,只需证明PSPACE完备语言TQBF属于IP类就足够了。令φ为带有以下形式量词的逻辑公式

Concept of the Proof Let us first try to use the idea used in the previous proof and identify where the difficulties arise. To show that every language of the class PSPACE belongs to the class IP, it suffices to show that the PSPACE-complete language TQBF belongs to the class IP. Let φ be a Boolean formula with quantifiers of the form

φ = Q 1 x 1 Q 2 x 2 Q m x m [ Φ ],

φ = Q 1 x 1 Q 2 x 2 Q m x m [ Φ ],

其中Φ是 CNF 公式,每个符号Q i表示量词。我们将像以前一样定义函数f,但这次包括量词。对于 0 ≤ im i a 1 , …, a m {0, 1},令

where Φ is a CNF formula and each symbol Q i denotes a quantifier or . We define the functions f i as before, but this time including quantifiers. For 0 ≤ im and a 1 , …, a m {0, 1}, let

其中Φ ( a 1 , …, a i ) 是公式Φ,其中值a 1a i已替换x 1x i 的变量。因此,f 0 ()是公式φ的逻辑值。我们还有以下算术恒等式

where Φ ( a 1 , …, a i ) is the formula Φ in which the variables x 1 to x i are substituted with the values ​​a 1 to a i . Thus f 0 () is the logical value of the formula φ . We also have the following arithmetic identities

回想一下,我们将运算x * y定义为 1 − (1 − x )(1 − y )。

Recall that we defined the operation x * y as 1 − (1 − x )(1 − y ).

这里需要对#SAT语言的协议进行自然修改,包括将函数f i扩展到有限域并使用上述量词恒等式而不是和恒等式。然而,这个想法有一个问题,即通过算术化,每个量词都可以将所得多项式的次数加倍。因此,多项式的次数可以呈指数增长,这将导致验证器的运行时间变得呈指数增长,以便它能够处理专员作为多项式描述发送的指数数量的系数。

A natural modification of the protocol for the #SAT language is to extend the function f i to a finite field and use the above identities for quantifiers instead of the identities for sums. This idea, however, is associated with the problem that in arithmetization, each quantifier can double the degree of the resulting polynomial. The degrees of the polynomials can therefore grow exponentially, which would make the Verifier's running time exponentially long, so that it can process exponentially many coefficients sent by the Advocate as polynomial descriptions.

为了保持多项式的次数较小,我们引入了归约运算R,它降低了多项式的次数而不改变其逻辑值的行为。

To keep the degrees of the polynomials small, we introduce a reduction operation R , which lowers the degree of the polynomials without changing their behavior for logical values.

证明 φ = Qx 1 Qx m [ Φ ] 为带量词的逻辑公式,其中Φ为 CNF 形式的公式。对于算术φ,我们引入一个表达式

Proof Let φ = Qx 1 Qx m [ Φ ] be a logical formula with quantifiers, where Φ is a CNF formula. To arithmetize φ , we introduce the expression

φ ' = Qx 1 Rx 1 Qx 2 Rx 1 Rx 2 Qx 3 Rx 1 Rx 2 Rx 3 Qx m Rx 1 Rx m [ Φ ]。

φ ' = Qx 1 Rx 1 Qx 2 Rx 1 Rx 2 Qx 3 Rx 1 Rx 2 Rx 3 Qx m Rx 1 Rx m [ Φ ].

现在,我们不关心Rx符号的含义。仅在定义函数f i时才需要它们。我们将公式φ ' 写为

For now, we don't care about what the symbols Rx and mean . They are only needed when defining the functions f and . We will write the formula φ ' as

φ ' = S 1 y 1 S 2 y 2 S k y k [ Φ ],

φ ' = S 1 y 1 S 2 y 2 S k y k [ Φ ],

其中每个S i { , , R } 且y i { x 1 , …, x m }。

where each S i { , , R } and y i { x 1 , …, x m }.

对于每个ik,我们定义一个函数f i。令f k ( x 1 , …, x m ) 为对Φ进行算术运算得到的多项式p ( x 1 , …, x m ) 。对于i < k,我们将f i定义为f i +1

For each ik we define a function f i . Let f k ( x 1 , …, x m ) be a polynomial p ( x 1 , …, x m ) obtained by arithmetization of Φ . For i < k we define f i in terms of f i +1 :

如果 S i +1是量词,则f if i +1少一个变量。如果 S+1R,则两个函数具有相同数量的变量。因此,函数f i一般不会有i 个变量。为了避免费力地编写索引,我们使用“...”而不是枚举1a j对应j值。此外,我们更改了函数参数的顺序,以便变量y+1显示为最后一个参数。

If S i +1 is a quantifier or , then f i has one less variable than f i +1 . If S i +1 is R , then both functions have the same number of variables. Therefore, the function f i will not have i variables in general . To avoid the laborious writing of indices, we have used "..." instead of calculating a 1 through a j for the corresponding values ​​of j . We have also changed the order of the function arguments so that the variable y i +1 appears as the last argument.

请注意,对多项式执行的Rx运算不会更改逻辑值参数的值。因此,f 0 ()仍然是公式φ的逻辑值。然而,我们可以看到Rx操作返回一个关于x线性的结果。我们在φ ' 公式中的Qx i之后添加了运算Rx 1 ... Rx i ,以便在由于Q i量词的算术化而对它们进行平方之前将每个变量的阶数降低到 1 。

Note that the operation Rx performed on polynomials does not change their values ​​for arguments that are logical values. Thus, f 0 () is still the logical value of the formula φ . However, we can see that the operation Rx returns a result that is linear in x . We added the operations Rx 1 Rx i after Q and x i in the formula φ ' to reduce the degree of each variable to 1 before they are squared due to the arithmetization of the quantifier Q i .

我们现在可以描述该协议。所有算术运算都在大小至少为 n 4的有限域F中执行,其中n是公式φ的长度 。验证者V可以自己找到这个大小的素数,因此P不必提供它。

We can now describe the protocol. All arithmetic operations are performed on a finite field F of size at least n 4 , where n is the length of the formula  φ . The verifier V can find a prime of this size on its own, so P does not need to provide it.

阶段 01P发送f 0 ()。1

Phase 0 . P transmits f 0 ().

P VP将f 0 ()发送到V

P V : P sends f 0 () to V .

V检查 f 0 () = 1 是否,如果不是,则拒绝

V checks if f 0 () = 1 and if not, rejects .

...

...

第一阶段。如果f i ( r 1 , r ) 正确,则1P使V相信值f i −1 ( r 1 ) 是正确的。 1

Phase i . P convinces V that the value f i −1 ( r 1 ) is correct if f i ( r 1 , r ) is correct.

P VP输出函数f( r 1 , z ) 的系数作为变量z的多项式。 (这里的符号r 1 表示之前随机选择的值r 1 , r 2 , … 。)

P V : P outputs the coefficients of the function f i ( r 1 , z ) as a polynomial in the variable z . (The notation r 1 here denotes the previously randomly selected values ​​r 1 , r 2 , … .)

V使用这些系数来计算f i ( r 1 , 0) 和f i ( r 1 , 1)。

V uses these coefficients to calculate f i ( r 1 , 0) and f i ( r 1 , 1).

V检查是否满足以下等式:

V checks whether the following equalities are met:

and

如果其中一个不为真,V 就会拒绝

If any of them are not met, V rejects .

V PVF中选择一个随机数r并将其发送给P。(当 S i = R时, r的这个值替换r的先前值。)

V P : V selects a random number r from the field F and sends it to P . (When S i = R , this value r replaces the previous value r .)

进入阶段i + 1,其中P必须使V相信f i ( r 1 , r )的值是正确的。

Proceed to phase i + 1, where P must convince V that the value of f i ( r 1 , r ) is correct.

...

...

阶段k+11V直接检查f k ( r 1 , …, r m )的值是否正确。

Phase k+1 . V directly checks that the value of f k ( r 1 , …, r m ) is correct.

V计算p ( r 1 , …, r m ) 并将结果与​​ f k ( r 1 , …, r m )的值进行比较。如果它们相等,则接受;否则它会拒绝

V computes p ( r 1 , …, r m ) and compares the result with the value it has for f k ( r 1 , …, r m ). If they are equal, accepts ; otherwise, rejects .

这样就完成了协议的描述。

This concludes the protocol description.

证明该协议的正确性类似于证明#SAT协议的正确性。显然,如果公式φ为真,则P可以遵循协议,V也会接受。如果公式φ为假,则必须位于相位 0,从而为f 0 () 发送错误值。在第i阶段,如果V对于f i −1 ( r 1 ... )具有无效值,则f i ( r 1 ... , 0) 和f i ( r 1 .. ) 的值之一. , 1) 一定是无效的,并且函数f的多项式一定是错误的。因此,对于r的随机值 , 在此阶段幸运的概率(因为f i ( r 1 ... , r ) 具有正确值)最多等于多项式的次数除以体,因此小于n / n 4。该协议运行O ( n2 ) 个阶段,因此P̃在某个阶段幸运的概率最多为 1/ n。如果在每个阶段都很幸运,V将拒绝阶段k +1中的证据。

The proof of the correctness of this protocol is similar to the proof of the correctness of the protocol for #SAT . It is obvious that if the formula φ is true, then P can follow the protocol and V will accept. If the formula φ is false, then must lie in phase 0, sending an incorrect value for f 0 (). In phase i , if V has an incorrect value for f i −1 ( r 1 ), then one of the values ​​f i ( r 1 , 0) and f i ( r 1 , 1) must be incorrect and the polynomial for the function f i must be wrong. Consequently, for a random value  r, the probability that will be lucky in this phase because f i ( r 1 , r ) has a correct value is at most equal to the degree of the polynomial divided by the size of the field, which is less than n / n 4 . The protocol runs for O ( n 2 ) phases, so the probability that is lucky in some phase is at most 1/ n . If is lucky in every phase, V will reject the proof in phase k + 1.

10.5

并行计算

10.5

Parallel Computing

并行计算机是一种可以同时执行多项操作的计算机。并行计算机可以比顺序计算机更快地解决某些问题,顺序计算机一次只执行一项操作。实际上,两种类型的计算机之间的界限有些模糊,因为大多数真实的计算机(包括“顺序”计算机)都被设计为在执行单个指令时使用某种类型的并行性。我们将重点关注大规模并行性,其中大量(我们的意思是数百万或更多)处理器积极参与单个计算。

A parallel computer is one that can perform many operations simultaneously. Parallel computers can solve certain problems much faster than sequential computers , which perform only one operation at a time. In practice, the line between the two types of computers is somewhat blurred, since most real-world computers (including "sequential" ones) are designed to use some form of parallelism in executing individual instructions. We will focus on massive parallelism, in which a large number (meaning millions or more) of processors are actively involved in a single calculation.

在本节中,我们将简要介绍并行计算的理论。我们将描述一个并行计算机模型,并用它来展示此类问题的示例,这些问题非常适合并行处理。我们还将研究一些不适合并行处理的问题。

In this section, we will give a brief introduction to the theory of parallel computing. We will describe the model of a parallel computer and use it to show examples of problems that are well suited to parallel processing. We will also examine some problems that are not suitable for parallel processing.

统一逻辑电路

Uniform logic circuits

并行算法理论研究中最流行的模型之一是并行随机存取 PRAM 。在 PRAM 模型中,具有在真实计算机上建模的简单指令集的理想处理器通过共享内存相互交互。在这一小节中,我们没有足够的空间来详细描述 PRAM 模型。相反,我们将使用我们在第 9 章中出于不同目的引入的替代并行计算机模型,即逻辑电路。

One of the most popular models in the theoretical study of parallel algorithms is the parallel random access machine ( PRAM ) . In the PRAM model , idealized processors with simple instruction sets modeled on real computers interact with each other via shared memory. We do not have the space to describe the PRAM model in detail in this short section. Instead, we will use an alternative model of the parallel computer that we introduced for a different purpose in Chapter 9, namely, the use of logical circuits.

逻辑电路作为并行计算的模型既有优点也有缺点。从积极的一面来看,我们可以提到模型描述的简单性,这使得进行证明变得更加容易。逻辑电路也与真实的硬件设计有明显的相似之处,在这方面,该模型是现实的。缺点包括由于各个处理器的弱点,电路的“编程”非常奇怪。此外,在我们对逻辑电路的定义中,我们排除了循环的可能性,而不是实际可以构建的电路。

Logical circuits as a model of parallel computation have both advantages and disadvantages. On the positive side, we can mention the simplicity of the model description, which makes it easy to perform proofs. Logical circuits also bear an obvious resemblance to real hardware designs, and in this respect the model is realistic. On the negative side, we can mention that the "programming" of the circuits is rather eccentric, due to the weakness of the individual processors. Furthermore, in our definition of logical circuits, we have excluded the possibility of cycles, unlike circuits that can actually be built.

在基于逻辑电路的并行计算机模型中,我们假设每个门都是一个单独的处理器,因此我们将处理器复杂度定义为逻辑电路的大小。我们假设每个处理器在单个步骤(时间单位)中计算其功能,因此我们可以将逻辑电路的并行时间复杂度定义为其深度,即从输入变量到输出门的最大距离(最长路径)。

In the model of a parallel computer based on logical circuits, we assume that each gate is an individual processor, so we define the processor complexity as the size of the logical circuit. We assume that each processor computes its function in a single step (time unit), so we can define the parallel time complexity of a logical circuit as its depth , which is the largest distance (longest path) from the input variable to the output gate.

每个特定电路都有固定数量的输入变量,因此我们将使用定义 9.27 中介绍的电路族来解析语言。我们需要对电路系列施加一些技术限制,以使它们与其他并行计算模型(例如 PRAM)兼容,其中单个机器能够处理任意长度的输入字。这个约束确保我们可以轻松获得电路系列的每个成员。这种一致性要求是合理的,因为如果这种电路难以构建,仅仅知道有一些小电路可以解析语言的某些元素并不是很有用。这导致了以下定义。

Each particular circuit has a fixed number of input variables, so we will use the circuit families introduced in Definition 9.27 to resolve languages. We must impose a technical constraint on the circuit families to make them compatible with other models of parallel computation, such as PRAM, where a single machine can handle input words of arbitrary lengths. This constraint ensures that we can easily obtain every member of the circuit family. This requirement of uniformity is reasonable, since simply knowing that there is some small circuit that resolves certain elements of a language is not very useful if such a circuit is difficult to construct. This leads to the following definition.

定义10.34

Definition 10.34

如果有一个传感器T在对数存储器中运行,对于输入字 1 n生成字< C n > ,则电路族 ( C 0 , C 1 , C 2 …) 是酉的

A family of circuits ( C 0 , C 1 , C 2 …) is unitary if there exists a transducer T operating on logarithmic memory which, for an input word 1 n , generates the word C n .

回想一下,在定义 9.28 中,我们根据最小尺寸和最小深度分辨率电路的尺寸和深度来定义语言的复杂性。在本节中,我们将同时考虑电路系列的大小和深度,以便能够确定需要多少个处理器才能实现给定的并行时间复杂度,反之亦然。我们说一种语言同时具有尺寸深度复杂度(尺寸-深度复杂度)至多等于 ( f ( n ), g ( n )) 如果对于该语言存在具有尺寸复杂度f的单一电路族( n ) 和关于深度g ( n ) 的复杂性。

Recall that in Definition 9.28 we defined the complexity of languages ​​with respect to the size and depth of their resolving circuits of minimal size and minimal depth. In this section we consider the size and depth of a family of circuits simultaneously in order to be able to determine how many processors we need to achieve a given parallel time complexity, or vice versa. We say that a language has simultaneous size and depth complexity (size-depth complexity) at most ( f ( n ), g ( n )) if there exists for this language a uniform family of circuits with size complexity f ( n ) and depth complexity g ( n ).

10.35

Example 10.35

A是字母表 {0,1} 上的一种语言,由包含奇数个 1 的所有单词组成。我们可以使用奇偶校验函数检查我们是否属于语言 A。我们可以使用标准 AND、OR 和 NOT 运算来实现具有两个输入x y的奇偶校验逻辑门,即 ( x Ø y ) x y )。令电路的输入变量为x 1 , ..., x n。获得奇偶校验函数电路的一种方法是构造门g i,使得g 1 = x 1g i = x i g i −1 ( in )。该结构的大小和深度均为O ( n )。

Let A be a language over the alphabet {0,1} consisting of all words containing an odd number of ones. We can check membership in the language A using the parity function. A parity-checking logic gate with two inputs x y can be implemented using the standard AND, OR, and NOT operations as ( x ¬ y ) x y ). Let the input variables of the circuit be x 1 , …, x n . One way to obtain a circuit for the parity function is to construct gates g i , such that g 1 = x 1 and g i = x i g i −1 for in . This construction is O ( n ) in size and depth.

在例 9.29 中,我们通过从⊕门构造二叉树,描述了奇偶校验函数的另一个电路,其大小为O ( n ),深度为O (log n ) 。此设计是一项重大改进,因为它使用的并行时间比本节前面介绍的设计要少得多。因此,语言A的大小和深度的复杂度是 (O( n ),O(log n ))。

In Example 9.29 we described another circuit for the parity function that was O ( n ) in size and O (log n ) in depth, by constructing a binary tree from gates . This construction is a significant improvement because it uses exponentially less parallel time than the one presented earlier in this section. Hence the size and depth complexity of A is (O( n ),O(log n )).

10.36

Example 10.36

回想一下,电路还可以用于计算返回单词作为输出的函数。考虑逻辑矩阵乘法函数。输入是 2 m 2 n 个变量,代表两个m × m矩阵,矩阵 = { a ik } 和矩阵 = { b ik }。输出是m 2 个值,代表m × m矩阵 C = { c ik },其中

Recall that circuits can also be used to compute functions that return words as output. Consider the Boolean matrix multiplication function . The input is 2 m 2 n variables, representing two m × m matrices , the matrix = { a ik } and the matrix = { b ik }. The output is m 2 values ​​representing the m × m matrix C = { c ik }, where

该函数的电路包含门g ijk ,用于计算ijk的合取a ij b jk。此外,对于i和 k,电路包含一个计算j g ijk的二元或门树。每个这样的树包含m -1 个 OR 门,深度为 log m。因此,逻辑矩阵乘法电路的大小为O ( m 3 )= O ( n 3/2 ),深度为O (log n )。

The circuit for this function contains gates g ijk that compute the conjunction a ij b jk for i , j , and k . Additionally, for i and  k the circuit contains a binary OR gate tree that computes j g ijk . Each such tree contains m −1 OR gates and has depth log m . Consequently, the circuits for Boolean matrix multiplication have size O ( m 3 ) = O ( n 3/2 ) and depth O (log n ).

10.37

Example 10.37

如果A = { a ij } 是m × m二元矩阵,则 A的传递闭包 就是该矩阵

If A = { a ij } is a binary m × m matrix , the transitive closure of A is the matrix

A A 2 A m ,

A A 2 A m ,

其中A i是矩阵A与其自身相乘i次的结果, 是对矩阵元素的各个位(按位)执行的 OR 运算。传递闭包操作与PATH问题密切相关,因此与 NL 类密切相关。如果A是有向图G的邻接矩阵,则A i是具有相同顶点的图的邻接矩阵,其中边表示图G中存在长度为i的路径。矩阵A的传递闭包是图的邻接矩阵,其中边表示图G中存在任意长度的路径。

where A i is the result of multiplying the matrix A by itself i times , and is the bitwise OR operation performed on the individual bits ( bitwise ) of the matrix elements. The operation of transitive closure is closely related to the PATH problem , and hence to the class NL. If A is the adjacency matrix of a directed graph G , then A i is the adjacency matrix of a graph with the same vertices such that an edge signals the existence of a path of length i in the graph G. The transitive closure of A is the adjacency matrix for a graph such that an edge signals the existence of a path of arbitrary length in the graph G.

我们可以将矩阵A i的计算表示为大小为i、深度为 log i的二叉树,其中每个顶点计算其下方两个矩阵的乘积。这些顶点中的每一个都是通过大小为O ( n 3/2 )的周长和对数深度来计算的。因此,计算A m 的电路具有大小O ( n 2 ) 和深度O ( log 2 n )。必须为每个A i构建一个电路,这会在尺寸计算中引入额外的因子m和深度O (log n )的额外层。因此,传递闭包问题的大小深度复杂度为 ( O ( n 5/2 ), O (log 2n ) )。

We can represent the computation of a matrix A i as a binary tree of size i and depth log i , where each vertex computes the product of the two matrices below it. Each of these vertices is computed by a circuit of size O ( n 3/2 ) and log depth. Hence the circuit computing A m has size O ( n 2 ) and depth O (log 2 n ). We need to construct a circuit for each A i , which introduces an additional factor m to the computation of size and an additional layer of depth O (log n ). Hence the size-depth complexity of the transitive closure problem is ( O ​​( n 5/2 ), O (log 2 n )).

数控类

NC Class

对于某个常数k,许多有趣的问题的大小深度复杂度约为 ( O ( n k ), O (log k n )) 。可以认为此类问题很容易通过中等数量的处理器并行化。这给我们带来了以下定义。

Many interesting problems have size-depth complexity of the order of ( O ( n k ), O (log k n )) for some constant k . Such problems can be considered as easy to parallelize with a moderate number of processors. We thus arrive at the following definition.

定义10.38

Definition 10.38

对于i ≥ 1,令NC i为可以使用多项式大小和深度 O(log i n )的统一3族电路来解析的语言类。令NC为属于 NC对于某些i 的语言类。由此类电路族计算的函数称为NC i可计算NC 可计算4

For i ≥ 1, let NC i be the class of languages ​​that can be decided by a uniform 3- family of circuits of polynomial size and depth O(log i n ). Let NC be the class of languages ​​that belong to NC i for some i . Functions computed by such families of circuits are called NC i -computable or NC-computable 4 .

我们将探讨这些复杂性类别与我们之前遇到的其他语言类别之间的关系。首先,我们将找到图灵机的内存复杂度和电路深度之间的联系。对数深度电路可解决的问题也可在对数存储器中解决。相反,在对数存储器中可解决的问题,即使是不确定的,也可以使用平方对数深度电路来解决。

We will examine the relationships between these complexity classes and other classes of languages ​​that we have encountered earlier. First, we will find a connection between the memory complexity of a Turing machine and the depth of the circuit. Problems solvable by circuits of log depth are also solvable in log memory. Conversely, problems solvable in log memory, even nondeterministically, are solvable by circuits of quadratic log depth.

定理10.39

Theorem 10.39

NC 1 L

NC 1 L.

证明 我们将草拟一个在对数存储器中运行的算法,该算法解析属于NC 1类的语言A。对于长度为输入字w 算法可以从语言A的统一电路族中构造第 n 个电路所需的描述然后,该算法可以使用来自输出门的深度优先搜索来计算该电路的值。此搜索仅需要内存来存储当前检查的门的路径以及迄今为止在该路径上获得的部分结果。该电路具有对数深度,因此对数内存足以进行模拟。

Proof We sketch an algorithm operating in logarithmic memory that resolves a language A of class NC 1 . Given an input word w of length n, the algorithm can construct the description required for the nth circuit of a uniform family of circuits for the language A . The algorithm can then compute the value of this circuit using a depth-first search from the output gate. This search requires memory only to store the path to the gate currently being probed and the partial results obtained on that path so far. The circuit has logarithmic depth, so logarithmic memory is sufficient for simulation.

定理10.40

Theorem 10.40

NL NC 2

NL NC 2 .

证明的概念 我们将计算属于 NL 类的机器的配置图的传递闭包。输出将是矩阵中对应于从初始配置到接受配置的路径的存在的条目。

Proof Concept We will compute the transitive closure of a machine configuration graph belonging to class NL. The output will be an entry in the matrix corresponding to the existence of a path from the initial configuration to the accepting configuration.

证明 A是由NL 类机器M解析的语言,其中A使用字母表 {0,1} 进行编码。语言A构建一个统一的电路族( C 0 C 1,...)。为了获得C n ,我们针对长度为n 的输入词w构建类似于机器M的计算图的图G。在构建系统时,我们不知道输入单词w - 只知道它的长度n。电路的输入变量w 1 ,…, w n对应于输入字的各个符号。

Proof Let A be a language resolved by a machine M of class NL, where A is encoded using the alphabet {0,1}. We construct a uniform family of circuits ( C 0 , C 1 , …) for the language A . To obtain C n , we construct a graph G similar to the graph of M 's computationsfor an input word w of length n . At the time of construction, we do not know the input word w – only its length n . The input variables of the circuit w 1 , …, w n correspond to the individual symbols of the input word.

回想一下,单词w的机器配置M描述了状态、构建带的内容以及输入带和构建带上的磁头位置,但不包括单词w本身。因此w的机器配置集M实际上并不依赖于单词w,而仅依赖于它的长度n。这些配置的数量是关于n的多项式,构成了图G的顶点。

Recall that the configuration of machine M for word w describes the state, the contents of the work tape, and the positions of the heads on the input and work tapes, but does not include the word w itself . Thus, the set of configurations of machine M for w does not actually depend on the word w , but only on its length n . These configurations, the number of which is polynomial in n , constitute the vertices of the graph G .

图G的边用中的输入变量标记。如果c 1c 2是图G的两个顶点,并且c 1表示输入头位于位置i ,我们在图G中创建一条边 ( c 1 , c 2 ) ,标签i(或at i),如果机器M根据其转换函数,当输入头读为 1(分别为 0)时,可以一步从配置c 1转换到配置c 2 。如果配置c 1可以一步生成配置c 2 ,无论输入头读取什么,我们都不会标记该边。

The edges of the graph G are labeled with input variables w i . If c 1 and c 2 are two vertices of the graph G and c 1 indicates that the input head is at position i , we create an edge in G ( c 1 , c 2 ) with label w i (or w i ) if the machine M , according to its transition function, can go from configuration c 1 to c 2 in one step when the input head reads 1 (or 0, respectively). If configuration c 1 can result in configuration c 2 in one step regardless of what the input head reads, we leave this edge unlabeled.

如果我们在图G中创建一组与长度为n的输入单词w相对应的边,当且仅当机器M接受单词w时,该图才会有一条从初始配置到接受配置的路径。因此,计算G的传递闭包并返回指示此类路径存在的位置的电路​​恰好接受属于A 的长度为n 的单词。这种电路的多项式大小和深度为O (log 2 n )。

Given a set of edges of a graph G corresponding to an input word w of length n , there will exist a path in the graph from the initial configuration to an accepting configuration if and only if the machine M accepts the word w . Thus, a circuit that computes the transitive closure of G and returns an entry that indicates the existence of such a path accepts exactly those words of length n that belong to A . Such a circuit has polynomial size and depth O (log 2 n ).

在对数存储器中运行的传感器能​​够构造G ,因此能够构造用于输入字1 n的电路C n。有关在对数存储器中运行的类似传感器的更详细描述,请参见定理 8.25。

The converter operating on logarithmic memory is able to construct G , and hence the circuit C n for the input word 1 n . See Theorem 8.25 for a more detailed description of a similar converter operating on logarithmic memory.

在多项式时间内可解决的问题类别包括在 NC 类别中可解决的所有问题,如下一个定理所示。

The class of problems solvable in polynomial time contains all problems solvable in the class NC, as the next theorem shows.

定理 10.41

Theorem 10.41

NC P

NC P.

证明 多项式算法可以运行在对数存储器中运行的传感器来生成电路C n,然后针对长度为n的输入字模拟其操作。

Proof A polynomial-time algorithm can run a transducer operating on logarithmic memory to generate a circuit C n , and then simulate its operation for an input word of length n .

P-完整性

P-completeness

我们现在考虑所有属于 P 类的问题也属于 NC 类的可能性。这些类之间的平等会令人惊讶,因为这意味着在多项式时间内可解决的所有问题都可以高度并行化。我们引入 P-完备性的概念来提供理论证明,证明属于 P 类的某些问题本质上是顺序的。

We now consider the possibility that all problems belonging to the class P also belong to the class NC. The equality between these classes would be surprising, since it would mean that all polynomial-time problems are highly parallelizable. We introduce the notion of P-completeness to provide a theoretical proof that certain problems belonging to the class P are sequential in nature.

定义10.42

Definition 10.42

语言BP 完备的,如果

A language B is P-complete if

  1. B P;
  2. B P;
  3. 属于 P 类的每个语言A都可以对数简化为语言B。
  4. every language A belonging to the class P is reducible in logarithmic memory to language B .

下一个定理与定理 8.23 的精神相同,并且具有类似的证明,因为 NC 电路族可以执行对数内存的约简。我们将这个定理的证明留给读者作为练习 10.3。

The next theorem is in the same spirit as Theorem 8.23 ​​and has a similar proof, since families of NC circuits can perform reductions in logarithmic memory. We leave the proof of this theorem to the reader as Exercise 10.3.

定理 10.43

Theorem 10.43

如果A ≤ L BB属于 NC 类,则语言A属于 NC 类。

If A ≤ L B and B belongs to the class NC, then the language A belongs to the class NC.

我们将证明计算逻辑电路值的问题是 P 完备的。对于电路C和输入变量x的值,我们将用C ( x ) 表示电路C对于x的值。让

We will show that the problem of computing the value of a logical circuit is P-complete. For a circuit C and input variables x we ​​will represent by C ( x ) the value of the circuit C for x . Let

CIRCUIT-VALUE = { C , x C是逻辑电路,C ( x ) = 1 }。

CIRCUIT-VALUE = { C , x : C is a logical circuit and C ( x ) = 1}.

定理 10.44

Theorem 10.44

CIRCUIT-VALUE问题是 P 完备问题。

The CIRCUIT-VALUE problem is P-complete.

证明 定理 9.30 的证明中提出的构造显示了如何将属于 P 类的任何语言简化为电路值问题。对于输入词w, reduce 创建一个模拟语言 A 图灵机的电路,以多项式时间运行。电路的输入是单词w本身。由于所创建的电路具有简单且可重复的结构,因此可以在对数存储器中进行简化。

Proof The construction in the proof of Theorem 9.30 shows how to reduce any language of class P to the CIRCUIT-VALUE problem . For an input word w , the reduction constructs a circuit that simulates a Turing machine for language A, running in polynomial time. The input to the circuit is the word w itself . The reduction can be performed in logarithmic memory, since the resulting circuit has a simple and repeatable structure.

10.6

密码学

10.6

Cryptography

使用密码进行加密以确保通信机密性的做法可以追溯到数千年前。在罗马时代,朱利叶斯·凯撒加密了发送给他的将军的信息,以保护他们免受可能的拦截。最近,图灵机的发明者艾伦·图灵带领一群英国数学家破解了二战期间使用的德国密码,向在大西洋巡逻的潜艇传输指令和命令。政府仍然依赖密码,并投入大量精力寻找难以破解的密码,以及寻找其他人使用的密码的弱点。如今,公司和个人也使用加密来提高信息的安全性。很快,几乎所有电子通信都将受到加密保护。

The practice of using secret codes to keep communications confidential dates back thousands of years. In Roman times, Julius Caesar encrypted messages to his generals to protect them from possible interception. More recently, Alan Turing, the inventor of the Turing machine, led a team of British mathematicians who broke the German ciphers used during World War II to send instructions and orders to U-boats patrolling the Atlantic. Governments still rely on secret codes and put a lot of effort into finding ciphers that are difficult to break and finding weaknesses in the ciphers used by others. Today, corporations and individuals also use encryption to increase the security of their information. Soon, almost all electronic communications will be protected by cryptography.

近年来,计算复杂性理论引发了秘密密码设计的一场革命。据我们所知,密码学领域现在已远远超出了私人通信的加密范围,并解决了广泛的信息安全问题。例如,有一种技术可以对消息进行数字“签名”以确认发送者的身份。我们知道电子选举方法,参与者通过互联网投票,结果可以公开宣布,而不会透露任何人的投票,同时防止多重投票和其他程序违规。我们可以创建新型密码,不需要参与者提前就加密和解密算法达成一致。

In recent years, computational complexity theory has led to a revolution in the design of secret ciphers. The field of cryptography, as we understand it, now extends far beyond the encryption of private communications to a wide range of information security problems. For example, there is technology that allows messages to be digitally "signed" to confirm the identity of the sender. We have methods of electronic elections in which participants vote over a network and the results can be announced publicly without revealing any individual's vote, while at the same time preventing multiple voting and other procedural violations. We can create new types of ciphers that do not require participants to agree on encryption and decryption algorithms in advance.

密码学是复杂性理论的重要实际应用。移动电话、卫星电视和电子商务都依赖于加密手段来保护信息。密码方法已经或将在大多数人的生活中发挥重要作用。事实上,密码学刺激了复杂性理论和其他数学领域的大量研究。

Cryptography is an important practical application of complexity theory. Mobile telephony, satellite television, and e-commerce all depend on cryptographic means of securing information. Cryptographic methods already play, or will play, an important role in most people's lives. In fact, cryptography has stimulated much of the research in complexity theory and other areas of mathematics.

密钥

Secret keys

传统上,当发送者想要加密消息以便只有特定接收者可以解密它时,发送者和接收者必须具有共享密钥。密钥是加密和解密算法使用的信息。确保密钥的保密性对于密码的安全性至关重要,因为任何有权访问密钥的人都可以加密和解密消息。

Traditionally, when a sender wants to encrypt a message so that only a specific recipient can decrypt it, the sender and recipient must share a secret key . The secret key is the information that is used by the encryption and decryption algorithms. Ensuring the secrecy of the key is critical to the security of the cipher, since anyone with access to the key can encrypt and decrypt messages.

通过完整检查所有可能的密钥可以发现太短的密钥。即使是稍长的密钥也可能容易受到某些类型的攻击,我们将很快介绍。实现完美加密安全的唯一方法是使用与所传输的所有消息的总长度一样长的密钥。

A key that is too short can be discovered by a complete review of all possible keys. Even slightly longer keys can be vulnerable to certain types of attacks, which we will discuss shortly. The only way to achieve perfect cryptographic security is to use keys that are as long as the total length of all transmitted messages.

长度至少等于消息总和的密钥称为一次性密钥。基本上,一次性密钥的每一位仅使用一次来加密消息的一位,之后该密钥的该位将被丢弃。使用一次性密钥的主要问题是,如果需要传输大量信息,则密钥需要相当长。对于大多数应用来说,一次性钥匙太笨重而不实用。

A key whose length is at least as long as the total sum of the message is called a one-time pad . Generally, each bit of the one-time pad is used only once to encrypt one bit of the message, after which that bit of the key is discarded. The main problem with using one-time pads is that they must be quite long if a significant amount of information is expected to be transmitted. For most applications, one-time pads are too cumbersome to be considered practical.

优选使用中等大小的密钥时允许安全传输无限量信息的加密代码。有趣的是,原则上不允许这种密码存在,但矛盾的是,它们在实践中得到了使用。这种类型的密码不可能存在,因为可以通过暴力搜索整个可能密钥空间来找到比交换消息的总长度短得多的密钥。因此,基于这种密钥的密码原则上是可以破解的。但这就是对这个悖论的解释。该密码在实践中可以提供足够的安全性,因为对于中等长度的密钥(例如,大约 100 位)来说,强力搜索非常长。当然,如果可以通过其他更快的方式破解密码,则它是不安全的,不应使用。困难在于确保密码不能被快速破解。

A cryptographic code that allows for the secure transmission of an unlimited amount of information and at the same time uses moderately sized keys is preferred. Interestingly, such ciphers have no right to exist in principle, but, paradoxically, they are used in practice. Such ciphers cannot exist, because a key that is significantly shorter than the total length of the exchanged messages can be found by brute-force searching the entire space of possible keys. Therefore, a cipher based on such a key is in principle breakable. However, this is where the explanation of the paradox lies. The cipher can provide sufficient security in practice, because brute-force searching is incredibly long even for keys of average length - say, of the order of 100 bits. Of course, if the cipher can be broken in some other, faster way, then it is not secure and should not be used. The difficulty is to make sure that the cipher cannot be broken quickly.

目前,我们无法确保使用中等长度密钥的密码实际上是安全的。为了保证密码不能被快速破解,我们需要数学证明,至少不能快速找到密钥。然而,这种证明似乎超出了现代数学的能力!这是因为一旦发现密钥,就可以通过检查用它加密的消息来轻松验证其有效性。因此,密钥验证问题可以表述为 P 类问题,如果我们能够证明在多项式时间内无法找到密钥,那么这将是证明 P 类与 NP 类不同的数学上的巨大进步。

At present, we know of no way to ensure that a cipher using medium-length keys is truly secure. To guarantee that the cipher cannot be quickly broken, we need a mathematical proof that, at a minimum, the key cannot be quickly found. But such proofs seem to be beyond the capabilities of modern mathematics! This is because once a key has been discovered, its correctness can be easily verified by examining messages encrypted using it. Thus, the problem of key verification can be formulated as a problem in the class P. If we could prove that keys cannot be found in polynomial time, it would be a great mathematical step towards proving that P is distinct from NP.

由于我们无法从数学上证明密码是牢不可破的,因此我们必须依赖间接证据。过去,密码质量的证明是通过聘请专家尝试破解密码来获得的。如果他们无法做到这一点,人们对他的安全的信心就会增加。这种方法有明显的弱点。如果有人拥有比我们更好的专家,或者如果我们不信任自己的专家,那么密码的可靠性就会受到质疑。然而,直到最近,这种方法还是唯一可能的方法,并用于确保广泛使用的密码的可靠性,例如美国国家标准与技术研究所批准的数据加密标准 (DES) 5 。

Since we cannot mathematically prove that ciphers are unbreakable, we must rely on circumstantial evidence. In the past, proof of a cipher's quality was obtained by hiring experts to try to break it. If they were unable to do so, confidence in its security increased. This approach has obvious weaknesses. If someone has better experts than we do, or if we do not trust our own experts, the reliability of the cipher is questionable. Nevertheless, this approach was the only possible one until recently, and it was used to ensure the reliability of widely used ciphers such as the Data Encryption Standard (DES) 5 , approved by the National Institute of Standards and Technology of the United States.

复杂性理论提供了另一种得出密码安全性强前提的方法。我们可以证明,破解密码问题的复杂性与另一个问题的复杂性有关,而另一个问题已经有令人信服的证据表明其无法解决。回想一下,我们使用 NP 完备性的概念来表明某些问题在计算上是困难的。将 NP 完备问题简化为密码破解问题应该表明密码破解问题本身是 NP 完备的。然而,这并不足以证明安全性,因为 NP 完整性的概念是基于最坏情况的复杂性定义的。一个问题可能是 NP 完备的,但通常很容易解决。然而,密码几乎总是难以破解,因此我们需要测量平均复杂性,而不是最坏情况的复杂性。

Complexity theory offers another way of achieving strong conclusions about the security of ciphers. We can show that the complexity of the problem of breaking a cipher is related to the complexity of another problem for which there is already convincing evidence of its unsolvability. Recall that we used the notion of NP-completeness to show that certain problems are computationally hard. Reducing an NP-complete problem to a problem of breaking a cipher should show that the problem of breaking a cipher is itself NP-complete. However, this is not a sufficient proof of security, since the notion of NP-completeness is defined in terms of worst-case complexity. A problem can be NP-complete and still be easy to solve in general. However, ciphers should almost always be hard to break, so we need to measure average complexity, not worst-case complexity.

在中间情况下被认为是困难的一个问题是因式分解问题(将整数因式分解为质因数)。几个世纪以来,它一直吸引着顶级数学家的注意力,但尚未有人找到解决该问题的快速方法。一些现代密码是建立在因式分解问题之上的,因此破解密码相当于对数字进行因式分解。对于这些密码的安全性来说,这是一个令人信服的前提,因为破解此类加密的有效方法将提供快速分解算法,这将是计算数论中的一项伟大成就。

One problem that is believed to be hard in the average case is the factoring problem (decomposing an integer into its prime factors). It has occupied the attention of the best mathematicians for centuries, but no one has yet discovered a fast procedure for solving it. Some modern ciphers are built on the factoring problem, so that breaking the cipher is equivalent to factoring the number. This is a convincing premise for the security of these ciphers, since an efficient way of breaking such an encryption would provide a fast factoring algorithm, which would be a major achievement in computational number theory.

公钥加密系统

Public Key Encryption Systems

即使密钥很短,其管理仍然对其在传统密码学中的广泛使用构成障碍。一个问题是,任何一对希​​望保持通信私密性的各方都必须建立一个共享密钥才能做到这一点。另一个问题是各方必须对迄今为止使用过的所有密钥保密。

Even when cryptographic keys are short, key management still poses an obstacle to their widespread use in conventional cryptography. One problem is that each pair of parties that wish to ensure the privacy of their communications must establish a shared secret key to do so. Another problem is that each party must keep secret all the keys it has used so far.

公钥加密系统的最新发展为这两个问题提供了一个优雅的解决方案。在传统的密钥加密系统中,相同的密钥用于加密和解密。将此与现代公钥加密系统进行对比,其中解密密钥与加密密钥不同,并且无法轻松地从其中一个密钥计算出另一个密钥。

Recent advances in public-key encryption systems provide an elegant solution to both problems. In a traditional secret-key encryption system, the same key is used for both encryption and decryption. Contrast this with a modern public-key encryption system , where the decryption key is different from the encryption key, and one cannot be easily calculated from the other.

虽然这个想法看似简单,但分离这两个密钥会产生可怕的后果。现在通信的每一方只需要创建一对密钥:加密密钥E和解密密钥D。这些站点对D密钥保密,但公开共享E密钥。如果其他人想要向这样的人发送消息,他们会在公开可用的目录中找到E密钥,然后使用此密钥加密消息并从收件人发送消息。后者是唯一知道D密钥的人,因此只有他可以解密该消息。

While the idea is seemingly simple, separating the two keys has dire consequences. Now each party to the communication needs to create just one pair of keys: the encryption key E and the decryption key D . These parties keep key D secret, but publicly share key E . If someone else wants to send a message to that person, they look up key E in a publicly accessible directory, then encrypt the message using that key and send it away. The latter is the only person who knows key D , so only he can decrypt the message.

某些公钥加密系统也可用于实现 数字签名。如果发送者将其解密算法应用于正在发送的消息,则任何接收者都可以通过应用众所周知的加密算法来验证该消息是否确实来自该发送者。这样,发送者就有效地“签署”了该消息。这种使用假设加密和解密函数可以按任何顺序应用,就像 RSA 加密系统一样。

Certain public-key cryptography systems can also be used to implement digital signatures . If a sender applies their decryption algorithm to a message being sent, any recipient can verify that the message really came from that sender by applying a publicly known encryption algorithm. In this way, the sender effectively "signs" the message. This use assumes that the encryption and decryption functions can be applied in any order, as in the case of the RSA encryption system.

单向函数

One-way functions

现在我们将简要考虑构成现代密码学理论基础的两个概念,即单向函数侧入函数。使用复杂性理论作为密码学基础的优点之一是它允许您更轻松地制定分析安全性所需的假设。通过假设单向函数的存在,我们可以用密钥构建安全的加密系统。假设侧入函数的存在允许您构建公钥加密系统。这两种假设都有额外的理论和实践后果。在介绍一些介绍性概念后,我们将定义这两种类型的函数。

We now briefly consider two concepts that are the foundation of modern cryptography theory, namely one-way functions and side-entry functions . One advantage of using complexity theory as a foundation for cryptography is that it allows us to more easily formulate the assumptions necessary for analyzing security. The assumption of one-way functions allows us to construct secure secret-key encryption systems. The assumption of side-entry functions allows us to construct public-key encryption systems. Both assumptions have additional theoretical and practical consequences. We will define both types of functions after introducing a few introductory concepts.

如果对于每个字w,该字的长度与f ( w ) 相等,则函数f : Σ * Σ * 称为长度保留函数。如果长度保留函数从不为两个不同的字分配相同的值,即如果f ( x ) f ( y ) 对于x y ,则该函数是排列

A function f : Σ * Σ * is called a length-preserving function if for every word w the length of that word and f ( w ) are equal. A length-preserving function is a permutation if it never assigns the same value to two different words, that is, if f ( x ) f ( y ) for x y .

回想一下 10.2 节中提出的概率图灵机的定义。我们说概率图灵机M计算随机函数 M : Σ * Σ *,其中对于输入词w和计算出的输出x我们表示

Recall the definition of a probabilistic Turing machine given in Section 10.2. We say that a probabilistic Turing machine M computes a random function M : Σ * Σ *, where for an input word w and a computed output x we ​​denote

Pr[ M ( w ) = x ]

Pr[ M ( w ) = x ]

作为机器M停止在磁带上输入单词w的单词x 的接受状态的事件概率。请注意,M不必始终接受中的输入字,因此

as the probability of the event that machine M halts in the accepting state with word x on the tape for input word w . Note that M need not always accept input word w , so

Σ xΣ * Pr[ M ( w ) = x ] ≤ 1。

Σ xΣ * Pr[ M ( w ) = x ] ≤ 1.

现在我们可以继续讨论单向函数的定义。一般来说,如果一个函数易于计算但几乎总是难以反转,则该函数是单向的。在下面给出的定义中,f表示一个容易计算的单向函数,M表示一种多项式时间概率算法,我们可以将其视为试图反转函数f。我们将首先定义单向排列,因为这种情况稍微简单一些。

We can now move on to the definition of a one-way function. In general, a function is one-way if it is easy to compute but almost always hard to invert. In the definition below, f denotes an easily computable one-way function, and M denotes a polynomial-time probabilistic algorithm that we can think of as trying to invert f . We will first define one-way permutations, since this case is a bit simpler.

定义10.45

Definition 10.45

单向排列是满足以下条件的排列f :

A one-way permutation is a permutation f that satisfies the following conditions:

  1. 它可以在多项式时间内计算。
  2. It is computable in polynomial time.
  3. 对于任何在多项式时间内运行的概率图灵机M ,任何k且足够大的n ,如果我们随机选择长度为n的单词w并在输入单词f (w)上运行M ,则
  4. For any polynomial-time probabilistic Turing machine M , for any k and sufficiently large n , if we randomly choose a word w of length n and run M for an input word f ( w ), then

Pr M, w [ M ( f ( w )) = w ] ≤ n k

Pr M, w [ M ( f ( w )) = w ] ≤ n k .

在这种表示法中,Pr M, w是机器M做出的随机选择和随机单词选择w计算的概率。

In this notation Pr M, w denotes the probability calculated for random choices made by machine M and random selection of word w .

单向函数是满足以下条件的长度保留函数f 。

A one-way function is a length-preserving function f that satisfies the following conditions.

  1. 它可以在多项式时间内计算。
  2. It is computable in polynomial time.
  3. 对于任何在多项式时间内运行的概率图灵机M ,任何k且足够大的n ,如果我们随机选择长度为n的单词w并在输入单词f (w)上运行M ,则
  4. For any polynomial-time probabilistic Turing machine M , for any k and sufficiently large n , if we randomly choose a word w of length n and run M for an input word f ( w ), then

Pr M, w [ M ( f ( w )) = y,其中f ( y ) = f ( w )] ≤ n k

Pr M, w [ M ( f ( w )) = y , where f ( y ) = f ( w )] ≤ n k .

对于单向置换,任何概率多项式时间算法只有很小的概率成功反转函数f;换句话说, w不太可能f ( w )计算得出。对于单向函数,任何概率多项式时间算法都有很小的机会找到任何单词y,函数f将其转换为f ( w )。

For a one-way permutation, any probabilistic polynomial-time algorithm has only a small probability of succeeding in inverting f ; in other words, it is unlikely that w can be computed from f ( w ) . For a one-way function, any probabilistic polynomial-time algorithm has a small chance of finding any word y that f maps to f ( w ).

10.46

Example 10.46

乘法函数mult是单向函数的候选者。令Σ = {0,1} 并令每个单词w Σ * 值mult ( w ) 是表示单词w的前半部分和后半部分的乘积的单词。正式地,

The multiplication function mult is a candidate for a one-way function. Let Σ = {0,1} and let for each word w Σ * the value mult ( w ) be the word representing the product of the first and second half of the word w . Formally,

mult ( w ) = w 1 · w 2 ,

mult ( w ) = w 1 · w 2 ,

其中w = w 1 w 2使得 |1 | = |2 |或 |1 | = |2 | + 1 如果 ||很奇怪。12中的被视为二进制数。我们用前导零填充单词mult ( w ),使其与单词w具有相同的长度。尽管在整数分解问题的研究上付出了巨大的努力,但还没有已知的概率多项式算法可以对乘法函数 求逆,即使对于可能输入的多项式分数也是如此。

where w = w 1 w 2 such that | w 1 | = | w 2 | or | w 1 | = | w 2 | + 1, if | w | is odd. The words w 1 and w 2 are treated as binary numbers. The word mult ( w ) is padded with leading zeros so that it has the same length as the word w . Despite great efforts in research on the integer factorization problem, no probabilistic polynomial algorithm is known that can invert the function mult , even for a polynomial fraction of possible inputs.

如果我们假设单向函数的存在,我们就可以构建一个安全性可以得到证明的密钥加密系统。这种结构过于复杂,无法在此介绍。相反,我们将向您展示单向函数的另一种用途。

If we assume the existence of one-way functions, we can construct a secret-key encryption system that is provably secure. This construction is too complex to present here. Instead, we will show another application of one-way functions.

单向函数的一个简单应用是一种安全密码系统,我们可以证明它是安全的。在典型的密码系统中,用户必须输入密码才能访问特定资源。系统以加密形式存储用户密码数据库。密码经过加密以保护它们,以防数据库意外或故意暴露。密码数据库通常是共享的,以便各种程序可以读取它们并检查密码。当用户输入密码时,系统会通过加密密码并将其与数据库中存储的版本进行比较来验证密码。显然,难以逆向的加密方案是可取的,因为这将使得从加密形式获得未加密的密码变得困难。在这种情况下,自然的选择是单向函数。

A simple application of the one-way function is a secure password system, the security of which can be proven. In a typical password system, the user must enter a password to gain access to some resource. The system maintains a database of user passwords in an encrypted form. The passwords are encrypted to protect them in case the database is accidentally or intentionally disclosed. Password databases are often shared so that different programs can read them and check the passwords. When the user enters a password, the system checks its validity by encrypting it and comparing it with the version stored in the database. It is obvious that an encryption scheme that is difficult to reverse is desirable, since this will make it difficult to recover the unencrypted password from the encrypted form. The natural choice in this case is the one-way function.

具有侧入式功能

Side Entry Features

我们不知道单向函数的存在是否足以构建一个公钥加密系统。为了实现这个构造,我们将使用一个称为side-entry function 的相关对象,只要我们有一些特殊的信息,就可以有效地反转它。

We do not know whether the mere existence of one-way functions is sufficient to construct a public-key encryption system. To achieve such a construction, we use a related object called a side-entry function , which can be efficiently inverted if one has some special information.

首先,我们需要探索索引函数族的函数的概念。如果我们有一个函数族 { f i },其中i属于Σ *,那么我们可以将该族表示为一个函数fΣ * × Σ * Σ *,其中f ( i , w ) = fi ( w )对于所有数据和 我们将这样的函数f称为索引函数。如果 f 索引的每个函数f i都是长度保留函数,则我们称f是长度保留函数。

First, we need to analyze the notion of indexing functions of a family of functions. If we have a family of functions { f i } for i belonging to Σ *, then we can represent this family as a single function f : Σ * × Σ * Σ *, where f ( i , w ) = f i ( w ) for all given i and  w . Such a function f is called an indexing function. We say that f is a length-preserving function if each of the functions f i indexed by it is a length-preserving function.

定义10.47

Definition 10.47

函数f : Σ * × Σ * Σ * 是一个保长索引函数,存在辅助概率多项式时间图灵机和辅助函数h : Σ * × Σ * Σ *。三元组f Gh满足以下三个条件:

A side -entry function f : Σ * × Σ * Σ * is a length-preserving indexing function for which there exists an auxiliary probabilistic Turing machine running in polynomial time and an auxiliary function h : Σ * × Σ * Σ *. The triple f , G , and h satisfies the following three conditions:

  1. 函数fh可以在多项式时间内计算。
  2. The functions f and h are computable in polynomial time.
  3. 对于任何在多项式时间内运行的概率图灵机E,对于任何k和足够大的n,如果我们选择一个由机器G对单词 1 n的(概率)操作产生的单词i , t ,以及一个随机单词w Σ n,则

    Pr E, w [ E ( i , fi ( w ) ) = y,其中fi ( y ) = fi ( w ) ] ≤ n k

  4. For any probabilistic Turing machine E running in polynomial time and for any k and sufficiently large n , if we choose a word i , t resulting from a (probabilistic) operation of the machine G for word 1 n , and a random word w Σ n , then

    Pr E, w [ E ( i , f i ( w )) = y , where f i ( y ) = f i ( w )] ≤ n k .

  5. 对于每个n 、长度为n的每个单词w以及机器G的每个输出单词 i, t ,对于某个输入单词以非零概率出现,以下成立
  6. For every n , every word w of length n and every output word i, t of the machine G , which occurs with non-zero probability for some input word, it holds

h ( t , fi ( w )) = y其中fi ( y ) = fi ( w )

h ( t , f i ( w )) = y , where f i ( y ) = f i ( w ).

概率图灵机G生成一个指向索引族中函数的索引i ,同时还生成一个值t ,该允许函数fi快速反转。条件 2 表明,如果t的值未知,则f i很难反转。条件 3 表明,当我们知道t时, f i可以很容易地求逆。h函数是反函数。

A probabilistic Turing machine G generates an index i pointing to a function from the indexed family, while generating a value t that allows the function f i to be quickly inverted . Condition 2 states that f i is intractable if the value of t is unknown. Condition 3 states that f i is easily inverted once t is known . The function h is an inverting function.

10.48

Example 10.48

现在我们将描述众所周知的 RSA 加密系统的侧入功能。我们描述相关的三元组fGh。发电机G的工作原理如下。对于输入单词 1,n随机选择两个长度为n的数字并检查它们的素数。如果它们不是素数,则重复抽奖,直到找到素数或达到预定义的时间限制并报告错误。找到数字pq 后,计算N = pqΦ ( N ) = ( p − 1)( q − 1)。它在 1 和Φ ( N ) 之间选择一个随机数e并检查它是否与Φ ( N )互质。如果不是,算法会选择另一个数字并再次检查。最后,该算法计算数字d ,它是数字eΦ ( N )的倒数。该运算是可行的,因为集合{1,…, Φ ( N )}中包含的互质数子集Φ ( N )通过模Φ ( N )相乘而形成群。最后,G返回结果 (( N , e ), d )。函数f的索引由两个数字Ne组成。让

We now describe the side-entry function that is the basis of the well-known RSA cryptographic system. We describe the associated triplet f , G , and h . The generator machine G works as follows. For an input word 1 n , it randomly selects two numbers of length n and checks for primality. If they are not prime, it repeats the selection until it finds primes or reaches a predetermined time limit and reports an error. After finding the numbers p and q , it computes N = pq and Φ ( N ) = ( p − 1)( q − 1 ). It selects a random number e between 1 and Φ ( N ) and checks whether it is coprime to Φ ( N ). If it is not, the algorithm selects another number and repeats the check. Finally, the algorithm computes a number d , which is the inverse of e modulo Φ ( N ). This operation is feasible because the subset of coprime numbers Φ ( N ) contained in the set {1, …, Φ ( N )} forms a group under multiplication modulo Φ ( N ). Finally, G returns the result (( N , e ), d ). The index of the function f consists of two numbers N and e . Let

f N, e ( w ) = we mod N

f N, e ( w ) = w e mod N .

反函数h

The inverting function h is

h ( d , x ) = x d mod N

h ( d , x ) = x d mod N .

函数h正确地反转g,因为h ( d , f N, e ( w )) = w ed mod N = w

The function h correctly inverts g , since h ( d , f N, e ( w )) = w ed mod N = w .

给定一个侧入函数(例如 RSA 函数),可以如下构建公钥加密系统。公钥是索引i,由概率机G生成。私钥是t的相应值。加密算法将消息m分成大小最多为log N的块。对于每个块发送方计算f i。生成的字符串是一条加密消息。接收方使用h函数从该密文中读取原始消息。

Given a side-entry function such as the RSA function, one can construct a public-key encryption system as follows. The public key is an index i , generated by a probabilistic machine G . The private (secret) key is the corresponding value t . The encryption algorithm divides the message m into blocks of size at most log N . For each block w , the sender computes f i . The resulting string of words is the encrypted message. The receiver uses the function h to deduce the original message from this ciphertext.

练习

Exercises

10.1证明深度为O (log n ) 的电路族也是多项式大小的族。

10.1 Prove that the family of circuits of depth O (log n ) is also a family of polynomial size.

10.2 证明数字 12 不是伪素数,因为它没有通过某个费马测试。

10.2 Show that the number 12 is not a pseudoprime, since it fails a certain Fermat test.

10.3 证明如果A≤L B且B属于NC类,则A属于NC类。

10.3 Prove that if AL B and B is a member of the class NC, then A is a member of the class NC.

10.4 证明具有n 个输入变量的奇偶校验函数可以通过具有O ( n ) 个顶点的分支的程序来计算。

10.4 Show that a parity function with n input variables can be computed by a branching program with O ( n ) vertices.

10.5 证明具有n 个输入变量的多数函数可以通过具有O ( n 2 ) 个顶点的分支的程序来计算。

10.5 Show that the majority function (majorant) of n input variables can be computed by a branching program with O ( n 2 ) vertices.

10.6 证明任何具有n 个输入变量的函数都可以使用具有O (2 n ) 个顶点的分支程序进行计算。

10.6 Show that any function with n input variables can be computed using a branching program that has O (2n ) vertices.

A 10.7 证明 BPP PSPACE。

A 10.7 Prove that BPP PSPACE.

任务

Tasks

10.8A是字母表 {0,1} 上的正则语言。证明A具有大小深度复杂度 ( O ( n ), O (log n ))。

10.8 Let A be a regular language over the alphabet {0,1}. Show that A has size-depth complexity ( O ( n ), O (log n )).

*10.9 逻辑公式是每个门只有一个输出的逻辑电路。相同的输入变量可以出现在公式中的多个位置。证明一种语言具有多项式大小公式族当且仅当它属于类 NC 1。跳过均匀性要求。

*10.9 A logical formula is a logical circuit in which each gate has only one output. The same input variable may appear in multiple places in the formula. Prove that a language has a family of polynomial-size formulas if and only if it belongs to the class NC 1 . Ignore the uniformity requirement.

*10.10 k头堆栈自动机k -PDA)是配备有k个双向只读头和读写堆栈的确定性堆栈自动机。让我们定义 PDA 类k = { A : Ak -PDA 识别}。证明 P = k PDA k。 (提示:回想一下,P 类等于在对数内存中运行的交替算法的类。)

*10.10 A k-head pushdown automaton ( k -PDA) is a deterministic pushdown automaton with k bidirectional read-only heads and a read-write stack. Define the class of PDAs k = { A : A is recognized by k -PDA}. Show that P = k PDA k . (Hint: Recall that the class P is equal to the class of alternating algorithms operating on logarithmic memory.)

10.11M是在多项式时间内运行的概率图灵机,并设C是一种语言,对于某些固定的 0 < ε 1 < ε 2 < 1,

10.11 Let M be a probabilistic Turing machine running in polynomial time and let C be a language such that for some fixed 0 < ε 1 < ε 2 < 1,

a. 如果w C,则 Pr[ M接受w ] < ε 1

a. if w C , then Pr[ M accepts w ] < ε 1 ;

b. 如果w C,则 Pr[ M接受w ] ≥ ε 2

b. if w C , then Pr[ M accepts w ] ≥ ε 2 .

证明C BPP。 (提示:使用引理 10.5 的结果。)

Prove that C BPP. (Hint: Use the result of Lemma 10.5.)

10.12 证明如果 P = NP,则 P = PH。

10.12 Prove that if P = NP, then P = PH.

10.13 证明如果 PH = PSPACE,则多项式时间层次结构只有有限多个不同的级别。

10.13 Show that if PH = PSPACE, then a polynomial time hierarchy has only finitely many distinct levels.

10.14 回想一下,NP SAT是一类由多项式时间非确定性图灵机解决的语言,具有可满足性问题的预言机。证明 NP SAT = Σ 2 P。

10.14 Recall that NP SAT is the class of languages ​​that are decided by polynomial-time nondeterministic Turing machines with an oracle for the satisfiability problem. Show that NP SAT = Σ 2 P.

*10.15 证明定理 10.6 中提出的费马小定理。 (提示:考虑值的序列a 1a 2、...。其中必须发生什么以及如何发生?)

*10.15 Prove Fermat's Little Theorem, given by Theorem 10.6. (Hint: Consider the sequence of values ​​a 1 , a 2 , … . What must happen in it and how?)

证明对于任何整数p > 1,如果p不是伪素数,则对于属于 Z p +的所有数字的至少一半,p无法通过费马测试。

Prove that for any integer p > 1, if p is not a pseudoprime, then p fails Fermat's test for at least half of all numbers in Z p + .

A* 10/16

A* 10.16

10.17 证明如果A { 0 , 1 } *是 L 类语言,则存在一系列分支程序(B 1 , B 2 , …),使得每个B n恰好接受属于A 的长度为n的单词并且每个程序的大小都是关于n 的多项式有界。

10.17 Prove that if A { 0 , 1 } * is a language of class L, then there exists a family of branching programs ( B 1 , B 2 , …) such that each B n accepts exactly words of length n from A, and the size of each of these programs is polynomially bounded in n .

10.18 证明如果A { 0 , 1 } *是正则语言,则存在一系列分支程序(B 1 , B 2 , …),使得每个B n恰好接受属于A 的长度为n的单词,并且这些程序中的每一个的大小都相对于n呈线性限制。

10.18 Prove that if A { 0 , 1 } * is a regular language, then there exists a family of branching programs ( B 1 , B 2 , …), such that each B n accepts exactly words of length n from A, and the size of each of these programs is linearly bounded in n .

10.19 证明如果 NP BPP,则 NP = RP。

10.19 Prove that if NP BPP, then NP = RP.

10.20 让我们将ZPP 机定义为概率图灵机,每个计算路径上允许三种类型的结果:接受拒绝如果ZPP M机器以至少 2/3 的概率返回每个单词w的正确答案(即,如果w A则接受,如果w A则拒绝),则它可以解析语言A ,并且从不给出错误答案。对于每个输入单词M可以返回?概率最多为 1/3。此外,机器M对单词w的所有计算路径的平均运行时间必须是关于单词w的长度的多项式有界。证明RP coRP = ZPP,其中ZPP是ZPP机器识别的语言集合。

10.20 Let us define a ZPP machine as a probabilistic Turing machine for which three kinds of outcomes are allowed on each computation path: accept , reject , and ? A ZPP machine M resolves a language A if for each word w it returns the correct answer (that is, it accepts if w A and rejects if w A ) with probability at least 2/3 and never gives an incorrect answer. For each input word M can return ? with probability at most 1/3. In addition, the average running time over all computation paths of M for a word w must be bounded polynomially in the length of the word w . Show that RP coRP = ZPP, where ZPP is the set of languages ​​recognized by ZPP machines.

10.21EQ BP = { < B 1 , B 2 >B 1B 2是等价的分支程序}。证明EQ BP语言是 coNP 完备的。

10.21 Let EQ BP = { B 1 , B 2 : B 1 and B 2 are equivalent branching programs}. Prove that the language EQ BP is coNP-complete.

10.22 设 BPL 为在对数内存中运行的概率图灵机以 1/3 的错误概率解析的语言集合。证明 BPL P。

10.22 Let BPL be the set of languages ​​that can be decided by probabilistic Turing machines operating on logarithmic memory with error probability 1/3. Prove that BPL P.

10.23CNF H = { 〈Φ>Φ是 CNF 形式的可满足公式,其中每个子句包含任意数量的文字,但最多有一个否定文字}。在问题 7.25 中,需要证明问题CNF H ∈ P。显示从CIRCUIT-VALUE语言到CNF H 的对数记忆减少,以表明CNF H语言是 P 完备的。

10.23 Let CNF H = { 〈Φ〉 : Φ be a satisfiable CNF formula in which each clause contains an arbitrary number of literals, but at most one negated literal}. In Problem 7.25, you were supposed to show that the CNF problem H P. Show a reduction in logarithmic memory from CIRCUIT-VALUE to CNF H to show that CNF H is P-complete.

精选解决方案

Selected solutions

10.7 如果M是在多项式时间内运行的概率图灵机,那么我们可以对其进行修改,以针对某个固定的r在每个计算路径上执行n r 次硬币翻转。因此,确定M接受输入单词的概率的问题归结为计算有多少接受路径并将该数字与 2/3·2 ( n r )进行比较。这些计算可以在多项式存储器中执行。

10.7 If M is a polynomial-time probabilistic Turing machine, then we can modify it so that it performs exactly n r coin tosses on each path of computation for some fixed r . Thus, the problem of determining the probability with which M accepts an input word is a matter of counting how many paths there are that accept and comparing this number with 2/3 2 ( n r ) . This computation can be performed in polynomial-time memory.

10.16如果p的费马测试失败,即如果a p −1 1 (mod p ), 我们将值 a 称为证人 Z * p为属于集合 {1, …, p − 1} 且与p互质的所有数字的集合。如果数p不是伪素数,则有一个见证a Z * p

10.16 Let us call a value a a witness if for this value the Fermata test of p fails, that is, if a p −1 1 (mod p ). Let Z * p be the set of all numbers belonging to the set {1, …, p − 1} that are coprime to p . If p is not a pseudoprime, then there exists a witness a Z * p .

我们可以使用a来获得更多证人。我们为每个非见证人找到属于Z * p的唯一见证人。如果d Z * p不是见证人,则d p −1 1 (mod p )成立。因此 ( da mod p ) p −1 1 (mod p ),所以da mod p是见证人。如果d 1d 2是不同的数且Z * p不是见证人,则d 1 a mod p d 2 a mod p。否则 ( d 1d 2 ) a 0 (mod p ),因此对于某个整数c , ( d 1d 2 ) a = cp。然而,d 1d 2属于 Z * p,因此 ( d 1d 2 ) < p,因此a = cp /( d 1d 2 ) 和p的公约数大于 1,这是不可能的因为a和 p互质。由此可见,集合 Z * p中的见证人数量必须至少与该集合中的非见证人数量一样多,因此 Z * p中至少有一半的元素是见证人。

We can use a to obtain more witnesses. We find a unique witness belonging to Z * p for each nonwitness. If d Z * p is not a witness, then d p −1 1 (mod p ). Hence ( da mod p ) p −1 1 (mod p ), so da mod p is a witness. If d 1 and d 2 are distinct numbers from Z * p that are not witnesses, then d 1 a mod p d 2 a mod p . Otherwise, ( d 1d 2 ) a 0 (mod p ), so ( d 1d 2 ) a = cp for some integer c . However, d 1 and d 2 are members of Z * p , so ( d 1d 2 ) < p , and so a = cp /( d 1d 2 ) and p have a common divisor greater than 1, which is impossible, since a and  p are relatively prime. It follows that the number of witnesses in the set Z * p must be at least as large as the number of nonwitnesses in that set, so at least half of the elements of Z * p are witnesses.

现在我们将证明每个与p不互质的元素Z + p都是见证者。如果bp具有公约数,则对于每个e > 0, bep具有相同的公约数。因此b p -1 1 (mod p )。由此我们可以得出结论,集合Z + p中至少有一半的元素是见证人。

We now show that every element of Z + p that is not relatively prime to p is a witness. If b and p have a common divisor, then b e and p have the same common divisor for all e > 0. Hence b p −1 1 (mod p ). We can conclude from this that at least half of the elements of Z + p are witnesses.

精选参考书目

Selected bibliography

ADLEMAN, L. 关于随机多项式时间的两种理论。第十九届 IEEE 计算机科学基础研讨会论文集( 1978),75-83。

ADLEMAN, L. Two theories on random polynomial time. In Proceedings of the Nineteenth IEEE Symposium on Foundations of Computer Science (1978), 75–83.

ADLEMAN, L. M. 和 HUANG, M. A. 在随机多项式时间内识别素数。第十九届 ACM 计算理论年度研讨会论文集(1987 年),462-469。

ADLEMAN, L. M. and HUANG, M. A. Recognizing primes in random polynomial time. In Proceedings of the Nineteenth Annual ACM Symposium on the Theory of Computing (1987), 462–469.

ADLEMAN, L. M.、POMERANCE, C. 和 RUMELY, R. S. 关于素数与合数的区别。数学年鉴 117 (1983), 173–206。

ADLEMAN, L. M., POMERANCE, C., and RUMELY, R. S. On distinguishing prime numbers from composite numbers. Annals of Mathematics 117 (1983), 173–206.

AGRAWAL, M.、KAYAL, N. 和 SAXENA, N. PRIMES 发表于 P. 《数学年鉴》,第二辑,第 160 卷,第 160 期。 2(2004),781-793。

AGRAWAL, M., KAYAL, N., and SAXENA, N. PRIMES is in P. The Annals of Mathematics , Second Series, vol. 160, no. 2 (2004), 781–793.

A. H. O.、A. V.、HOPCROFT、J. E. 和 ULLMAN, J. D.数据结构和算法。艾迪生韦斯利,1982。

A. H. O., A. V., HOPCROFT, J. E., and ULLMAN, J. D. Data Structures and Algorithms . Addison-Wesley, 1982.

AHO, A. V.、SETHI, R. 和 ULLMAN, J. D.编译器:原理、技术、工具。艾迪生韦斯利,1986。

AHO, A. V., SETHI, R., and ULLMAN, J. D. Compilers: Principles, Techniques, Tools . Addison-Wesley, 1986.

AKL,S.G.并行算法的设计与分析。普伦蒂斯霍尔国际,1989。

AKL, S.G. The Design and Analysis of Parallel Algorithms . Prentice-Hall International, 1989.

ALON, N.、ERDŐS, P. 和 SPENCER, J. H.概率方法。约翰·威利父子公司,1992 年。

ALON, N., ERDŐS, P., and SPENCER, J. H. The Probabilistic Method . John Wiley & Sons, 1992.

ANGLUIN, D. 和 VALIANT, LG 用于哈密顿电路和匹配的快速概率算法。计算机与系统科学杂志 18 (1979), 155–193。

ANGLUIN, D., and VALIANT, LG Fast probabilistic algorithms for Hamiltonian circuits and matchings. Journal of Computer and System Sciences 18 (1979), 155–193.

ARORA, S.、LUND, C.、MOTWANI, R.、SUDAN, M. 和 SZEGEDY, M. 近似问题的证明验证和硬度。第三十三届 IEEE 计算机科学基础研讨会论文集(1992 年),14-23。

ARORA, S., LUND, C., MOTWANI, R., SUDAN, M., and SZEGEDY, M. Proof verification and hardness of approximation problems. In Proceedings of the Thirty-third IEEE Symposium on Foundations of Computer Science (1992), 14–23.

BAASE, S.计算机算法:设计和分析简介。艾迪生韦斯利,1978。

BAASE, S. Computer Algorithms: Introduction to Design and Analysis . Addison-Wesley, 1978.

BABAI, L.电子邮件和互动的意想不到的力量。第五届复杂性理论结构年会论文集(1990),30-44。

BABAI, L. E -mail and the unexpected power of interaction. In Proceedings of the Fifth Annual Conference on Structure in Complexity Theory (1990), 30–44.

BACH, E. 和 SHALLIT, J.算法数论,第 1 卷。麻省理工学院出版社,1996。

BACH, E., and SHALLIT, J. Algorithmic Number Theory, Vol. 1 . MIT Press, 1996.

BALCÁZAR, J. L.、DIAZ, J. 和 GABARRÓ, J.结构复杂性 I, II . EATCS 理论计算机科学专着。施普林格出版社,1988 (I) 和 1990 (II)。

BALCÁZAR, J. L., DIAZ, J., and GABARRÓ, J. Structural Complexity I, I I. EATCS Monographs on Theoretical Computer Science. Springer Verlag, 1988 (I) and 1990 (II).

BEAME, P. W.、COOK, S. A. 和 HOOVER, H. J. 用于除法和相关问题的对数深度电路。SIAM 计算杂志 15, 4 (1986), 994–1003。

BEAME, P. W., COOK, S. A., and HOOVER, H. J. Log depth circuits for division and related problems. SIAM Journal on Computing 15, 4 (1986), 994–1003.

布卢姆,M.,钱德拉,A.,安德韦格曼,M.自由布尔图的等价性可以在多项式时间内概率性地确定。信息处理快报 10 (1980), 80–82。

BLUM,M., CHANDRA, A., ANDWEGMAN,M. Equivalence of free boolean graphs can be decided probabilistically in polynomial time. Information Processing Letters 10 (1980), 80–82.

BRASSARD, G. 和 BRATLEY, P.算法:理论与实践。普伦蒂斯·霍尔,1988。

BRASSARD, G., and BRATLEY, P. Algorithmics: Theory and Practice . Prentice-Hall, 1988.

CARMICHAEL, R. D. 关于满足费马同余a P−1 1 mod P的合数P《美国数学月刊》第 19 期(1912 年),22-27。

CARMICHAEL, R. D. On composite numbers P which satisfy the Fermat congruence a P−1 1 mod P . American Mathematical Monthly 19 (1912), 22–27.

CHOMSKY, N. 语言描述的三种模型。IRE 传输。信息论 2 (1956), 113–124。

CHOMSKY, N. Three models for the description of language. IRE Trans. on Information Theory 2 (1956), 113–124.

COBHAM, A. 函数的内在计算难度。国际逻辑、方法论和科学哲学大会录,Y. Bar-Hillel,编辑,北荷兰,1964 年,24-30。

COBHAM, A. The intrinsic computational difficulty of functions. In Proceedings of the International Congress for Logic, Methodology, and Philosophy of Science , Y. Bar-Hillel, Ed., North-Holland, 1964, 24–30.

COOK, SA 定理证明程序的复杂性。第三届 ACM 计算理论年度研讨会论文集(1971 年),151-158。

COOK, SA The complexity of theorem-proving procedures. In Proceedings of the Third Annual ACM Symposium on the Theory of Computing (1971), 151– 158.

CORMEN, T.、LEISERSON, C. 和 RIVEST, R.算法简介。麻省理工学院出版社,1989。

CORMEN, T., LEISERSON, C., and RIVEST, R. Introduction to Algorithms . MIT Press, 1989.

埃德蒙兹,J.路径、树木和花朵。加拿大数学杂志 17 (1965), 449–467。

EDMONDS, J. Paths, trees, and flowers. Canadian Journal of Mathematics 17 (1965), 449–467.

ENDERTON, H. B. 《逻辑的数学导论》。学术出版社,1972。

ENDERTON, H. B. A Mathematical Introduction to Logic . Academic Press, 1972.

EVEN,S.图算法。皮特曼,1979。

EVEN, S. Graph Algorithms . Pitman, 1979.

FELLER, W.概率论及其应用简介,第 1 卷。约翰威利父子公司,1970 年。

FELLER, W. An Introduction to Probability Theory and Its Applications, Vol. 1 . JohnWiley & Sons, 1970.

FEYNMAN, R. P.、HEY, A. J. G. 和 ALLEN, R. W. Feynman 关于计算的讲座。艾迪生韦斯利,1996。

FEYNMAN, R. P., HEY, A. J. G., and ALLEN, R. W. Feynman lectures on computation . Addison-Wesley, 1996.

GAREY, M. R. 和 JOHNSON, D. S.计算机和难处理性——NP 完备性理论指南。 W.H.弗里曼,1979。

GAREY, M. R., and JOHNSON, D. S. Computers and Intractability—A Guide to the Theory of NP-completeness . W. H. Freeman, 1979.

GILL, J. T. 概率图灵机的计算复杂性。SIAM 计算杂志 6, 4 (1977), 675–695。

GILL, J. T. Computational complexity of probabilistic Turing machines. SIAM Journal on Computing 6, 4 (1977), 675–695.

G ÖDEL, K. 《关于数学原理和相关系统中形式上不可判定的命题 I》。《不可判定》,M. Davis,编辑,Raven Press,1965 年,4-38。

G ÖDEL, K. On formally undecidable propositions in Principia Mathematica and related systems I. In The Undecidable , M. Davis, Ed., Raven Press, 1965, 4–38.

用于 MAX CUT 和 MAX 2SAT 的 GOEMANS、MX 和 WILLIAMSON、DP 0.878 近似算法。第二十六届 ACM 计算理论年度研讨会论文集(1994 年),422-431。

GOEMANS, MX, and WILLIAMSON, DP .878-approximation algorithms for MAX CUT and MAX 2SAT. In Proceedings of the Twenty-sixth Annual ACM Symposium on the Theory of Computing (1994), 422–431.

GOLDWASSER, S. 和 MICALI, S. 概率加密。计算机与系统科学杂志(1984),270-299。

GOLDWASSER, S., and MICALI, S. Probabilistic encryption. Journal of Computer and System Sciences (1984), 270–299.

GOLDWASSER, S.、MICALI, S. 和 RACKOFF, C. 交互式证明系统的知识复杂性。SIAM 计算杂志(1989),186–208。

GOLDWASSER, S., MICALI, S., and RACKOFF, C. The knowledge complexity of interactive proof-systems. SIAM Journal on Computing (1989), 186–208.

GREENLAW, R.、HOOVER, H. J. 和 RUZZO, W. L.并行计算的限制:P-完备性理论。牛津大学出版社,1995。

GREENLAW, R., HOOVER, H. J., and RUZZO, W. L. Limits to Parallel Computation: P-completeness Theory . Oxford University Press, 1995.

HARARY, F.图论,第 2 版。艾迪生韦斯利,1971。

HARARY, F. Graph Theory , 2d ed. Addison-Wesley, 1971.

HARTMANIS, J. 和 STEARNS, R. E. 关于算法的计算复杂性。美国数学会汇刊 117 (1965), 285–306。

HARTMANIS, J., and STEARNS, R. E. On the computational complexity of algorithms. Transactions of the American Mathematical Society 117 (1965), 285–306.

希尔伯特,D. 数学问题。 1900 年在巴黎举行的国际数学家大会上发表的演讲。《希尔伯特问题引起的数学发展》,第 28 卷。美国数学会,1976 年,1-34。

HILBERT, D. Mathematical problems. Lecture delivered before the International Congress of Mathematicians at Paris in 1900. In Mathematical Developments Arising from Hilbert Problems , vol. 28. American Mathematical Society, 1976, 1–34.

霍夫施塔特,D. R.戈德尔,埃舍尔,巴赫:永恒的金辫子。基础书籍,1979。

HOFSTADTER, D. R. Goedel, Escher, Bach: An Eternal Golden Braid . Basic Books, 1979.

HOPCROFT, J. E. 和 ULLMAN, J. D.自动机理论、语言和计算简介。艾迪生韦斯利,1979。

HOPCROFT, J. E., and ULLMAN, J. D. Introduction to Automata Theory, Languages ​​and Computation . Addison-Wesley, 1979.

IMMERMAN, N. 非确定性空间在补码下是封闭的。SIAM 计算杂志 17 (1988), 935–938。

IMMERMAN, N. Nondeterministic space is closed under complement. SIAM Journal on Computing 17 (1988), 935–938.

JOHNSON, D. S. NP 完整性专栏:有趣和利润的交互式证明系统。算法杂志 9, 3 (1988), 426–444。

JOHNSON, D. S. The NP-completeness column: Interactive proof systems for fun and profit. Journal of Algorithms 9, 3 (1988), 426–444.

KARP、RM 组合问题的可归约性。 《计算机计算的复杂性》(1972 年),R. E. Miller 和 J. W. Thatcher,编辑,Plenum Press,85-103。

KARP, RM Reducibility among combinatorial problems. In Complexity of Computer Computations (1972), R. E. Miller and J. W. Thatcher, Eds., Plenum Press, 85–103.

KARP, R. M. 和 LIPTON, R. J. 接受建议的图灵机。数学研究 28 (1982), 191-209

KARP, R. M., and LIPTON, R. J. Turing machines that take advice. Enseignement Mathématique 28 (1982), 191-209

KNUTH, DE 关于从左到右的语言翻译。信息与控制(1965),607-639。

KNUTH, DE On the translation of languages ​​from left to right. Information and Control (1965), 607–639.

LAWLER, E. L.组合优化:网络和拟阵。霍尔特、莱因哈特和温斯顿,1991。

LAWLER, E. L. Combinatorial Optimization: Networks and Matroids . Holt, Rinehart andWinston, 1991.

LAWLER, E. L.、LENSTRA, J. K.、RINOOY KAN, A. H. G. 和 SHMOYS, D. B.旅行商问题。约翰威利父子公司,1985 年。

LAWLER, E. L., LENSTRA, J. K., RINOOY KAN, A. H. G., and SHMOYS, D. B. The Traveling Salesman Problem . JohnWiley & Sons, 1985.

LEIGHTON, F. T.并行算法和架构简介:数组、树、超立方体。摩根·考夫曼,1991。

LEIGHTON, F. T. Introduction to Parallel Algorithms and Architectures: Array, Trees, Hypercubes . Morgan Kaufmann, 1991.

LEVIN, L. 通用搜索问题(俄语)。有问题的 Peredachi Informatsii 9, 3 (1973), 115–116。

LEVIN, L. Universal search problems (in Russian). Problemy Peredachi Informatsii 9, 3 (1973), 115–116.

刘易斯,H. 和帕帕迪米特里乌,C.计算理论的要素。普伦蒂斯·霍尔,1981。

LEWIS, H., and PAPADIMITRIOU, C. Elements of the Theory of Computation . Prentice-Hall, 1981.

LI, M. 和 VITANYI, P.柯尔莫哥洛夫复杂度及其应用简介。施普林格出版社,1993。

LI, M., and VITANYI, P. Introduction to Kolmogorov Complexity and its Applications . Springer-Verlag, 1993.

LICHTENSTEIN, D. 和 SIPSER, M. GO 是 PSPACE 难点。ACM 杂志(1980),393-401。

LICHTENSTEIN, D., and SIPSER, M. GO is PSPACE hard. Journal of the ACM (1980), 393–401.

LUBY, M.伪随机性和密码学应用。普林斯顿大学出版社,1996。

LUBY, M. Pseudorandomness and Cryptographic Applications . Princeton University Press, 1996.

LUND, C.、FORTNOW, L.、KARLOFF, H. 和 NISAN, N. 交互式证明系统的代数方法。ACM 杂志 39, 4 (1992), 859–868。

LUND, C., FORTNOW, L., KARLOFF, H., and NISAN, N. Algebraic methods for interactive proof systems. Journal of the ACM 39, 4 (1992), 859–868.

MILLER, G. L. 黎曼的假设和首要性检验。计算机与系统科学杂志 13 (1976), 300–317。

MILLER, G. L. Riemann's hypothesis and tests for primacy. Journal of Computer and System Sciences 13 (1976), 300–317.

NIVEN, I. 和 ZUCKERMAN, H.S.数论导论,第 4 版。约翰威利父子公司,1980 年。

NIVEN, I., and ZUCKERMAN, H. S. An Introduction to the Theory of Numbers , 4th ed. JohnWiley & Sons, 1980.

PAPADIMITRIOU,C.H.计算复杂性。艾迪生韦斯利,1994。

PAPADIMITRIOU, C. H. Computational Complexity . Addison-Wesley, 1994.

PAPADIMITRIOU, C. H. 和 STEIGLITZ, K.组合优化(算法和复杂性)。普伦蒂斯·霍尔,1982。

PAPADIMITRIOU, C. H., and STEIGLITZ, K. Combinatorial Optimization (Algorithms and Complexity) . Prentice-Hall, 1982.

PAPADIMITRIOU, C. H. 和 YANNAKAKIS, M. 优化、近似和复杂性类别。计算机与系统科学杂志 43, 3 (1991), 425–440。

PAPADIMITRIOU, C. H., and YANNAKAKIS, M. Optimization, approximation, and complexity classes. Journal of Computer and System Sciences 43, 3 (1991), 425–440.

POMERANCE, C. 关于伪素数的分布。计算数学 37 , 156 (1981), 587–593。

POMERANCE, C. On the distribution of pseudoprimes. Mathematics of Computation 37 , 156 (1981), 587–593.

PRATT,VR 每个素数都有一个简洁的证书。SIAM 计算杂志 4, 3 (1975), 214–220。

PRATT, VR Every prime has a succinct certificate. SIAM Journal on Computing 4, 3 (1975), 214–220.

密苏里州拉宾 概率算法。 《算法与复杂性:新方向和最新结果》,J. F. Traub,编辑,学术出版社 (1976) 21-39。

RABIN, MO Probabilistic algorithms. In Algorithms and Complexity: New Directions and Recent Results , J. F. Traub, Ed., Academic Press (1976) 21–39.

REINGOLD, O. 对数空间中的无向 ST 连接。ACM 杂志 55, 4 (2008), 1–24。

REINGOLD, O. Undirected st-connectivity in log-space. Journal of the ACM 55, 4 (2008), 1–24.

RIVEST, R. L.、SHAMIR, A. 和 ADLEMAN, L. 一种获取数字签名和公钥密码系统的方法。ACM 通讯 21, 2 (1978), 120–126。

RIVEST, R. L., SHAMIR, A., and ADLEMAN, L. A method for obtaining digital signatures and public key cryptosystems. Communications of the ACM 21, 2 (1978), 120–126.

ROCHE, E. 和 SCHABES, Y.有限状态语言处理。麻省理工学院出版社,1997。

ROCHE, E., and SCHABES, Y. Finite-State Language Processing . MIT Press, 1997.

SCHAEFER, T. J. 关于一些两人完美信息博弈的复杂性。计算机与系统科学杂志 16, 2 (1978), 185–225。

SCHAEFER, T. J. On the complexity of some two-person perfect-information games. Journal of Computer and System Sciences 16, 2 (1978), 185–225.

SEDGEWICK, R.算法,第 2 版。艾迪生韦斯利,1989。

SEDGEWICK, R. Algorithms , 2d ed. Addison-Wesley, 1989.

沙米尔,A. IP = PSPACE。ACM 杂志 39, 4 (1992), 869–877。

SHAMIR, A. IP = PSPACE. Journal of the ACM 39, 4 (1992), 869–877.

SHEN, A. IP = PSPACE:简化证明。ACM 杂志 39, 4 (1992), 878–880。

SHEN, A. IP = PSPACE: Simplified proof. Journal of the ACM 39, 4 (1992), 878–880.

SHOR、PW 量子计算机上素因数分解和离散对数的多项式时间算法。SIAM 计算杂志 26,(1997),1484–1509。

SHOR, PW Polynomial-time algorithms for prime factorization and discrete logarithms on a quantum computer. SIAM Journal on Computing 26 , (1997), 1484–1509.

SIPSER, M. 扫描自动机大小的下限。计算机与系统科学杂志 21, 2 (1980), 195–202。

SIPSER, M. Lower bounds on the size of sweeping automata. Journal of Computer and System Sciences 21, 2 (1980), 195–202.

SIPSER, M. P 与 NP 问题的历史和现状。第二十四届 ACM 计算理论年度研讨会论文集(1992 年),603-618。

SIPSER, M. The history and status of the P versus NP question. In Proceedings of the Twenty-fourth Annual ACM Symposium on the Theory of Computing (1992), 603–618.

STINSON, D. R.密码学:理论与实践。 CRC 出版社,1995 年。

STINSON, D. R. Cryptography: Theory and Practice . CRC Press, 1995.

SZELEPCSÉNYI, R. 非确定性自动机的强制枚举方法,Acta Informatica 26,(1988),279–284。

SZELEPCSÉNYI, R. The method of forced enumeration for nondeterministic automata, Acta Informatica 26 , (1988), 279–284.

TARJAN, R. E.数据结构和网络算法,第 44 卷 CBMS-NSF 应用数学区域会议系列,SIAM,1983 年。

TARJAN, R. E. Data structures and network algorithms , vol. 44 CBMS-NSF Regional Conference Series in Applied Mathematics, SIAM, 1983.

图灵,AM 关于可计算数,及其在 Entscheidungsproblem 中的应用。伦敦数学会论文集,(1936),230–265。

TURING, AM On computable numbers, with an application to the Entscheidungsproblem. In Proceedings , London Mathematical Society, (1936), 230–265.

ULLMAN, J. D.、A. H. O.、A. V. 和 HOPCROFT, J. E.计算机算法的设计和分析。艾迪生韦斯利,1974。

ULLMAN, J. D., A. H. O., A. V., and HOPCROFT, J. E. The Design and Analysis of Computer Algorithms . Addison-Wesley, 1974.

范·莱文,J.,编者。理论计算机科学手册A:算法和复杂性。爱思唯尔,1990。

VAN LEEUWEN, J., Ed. Handbook of Theoretical Computer Science A: Algorithms and Complexity . Elsevier, 1990.

脚注

Footnotes

第0章

Chapter 0

1在波兰语术语中,以这种方式定义的子图称为归纳图(波兰语版编者注)。

1 In Polish nomenclature, a subgraph defined in this way is called an induced graph (editor's note: Polish edition).

第1章

Chapter 1

1如果读者对符号δ : Q × Σ Q的含义有疑问,应返回第 7 页。

1 If the reader is in doubt about the meaning of the notation δ : Q × Σ Q , he should return to page 7.

2接受状态有时称为最终状态。

2 Accepting states are sometimes called final states.

3这样的表达式将M-接受状态为该对的两个元素都是接受状态的状态。在这种情况下, M仅接受自动机M 1M 2都接受的字符串,因此生成的语言将是交集,而不是并集。事实上,这个结果证明了正则语言的类在交集下是闭集的。

3 Such an expression would define the accepting states of M as those for which both members of the pair are accepting states. In such a case M would accept the sequence only if it is accepted by both automata M 1 and M 2 , so the resulting language would be an intersection, not a union. In fact, this result proves that the class of regular languages ​​is closed under intersection.

4该符号属于R 的每个可能的r 的集合δ ( r , a )之和。

4 The notation denotes the union of sets δ ( r , a ) for every possible r belonging to R .

5字符串的 长度是它包含的符号数。

5 The length of a string is the number of symbols it contains.

6见问题 1.48。

6 See issue 1.48.

7换句话说,我们需要呈现一个有限自动机N 1,为此构造的自动机N无法识别自动机N 1所描述的语言的闭包。

7 In other words, it is necessary to present a finite automaton N 1 for which the constructed automaton N 1 does not recognize the closure of the language described by the automaton N 1 .

8 回文是从左到右和从右到左读时具有相同形式的单词。

8 A palindrome is a word that has the same form when read from left to right and from right to left.

第2章

Chapter 2

1 DK这个名字可以看作是“确定性 K”的助记符,但它也代表了首先提出这一概念的 Donald Knuth 的名字缩写。

1 The name DK can be seen as a mnemonic for "deterministic K", but it also stands for the initials of Donald Knuth, who first proposed the concept.

第3章

Chapter 3

1其他一些教科书使用术语“递归可枚举语言”

1 In some other textbooks the term recursively enumerable language is used .

2其他一些教科书使用术语“递归语言”

2 In some other textbooks the term recursive language is used .

3这种要求的一个例子是能够在一个步骤中仅完成有限数量的工作。

3 An example of such a requirement is the ability to perform only a finite amount of work in one step.

4从德文原文翻译而来。

4 Translated from the original German.

第5章

Chapter 5

1从 LBA 的定义可以看出,当输入是空字 ε 时,磁带完备是空的,然后机器无法执行任何运动。这个技术问题可以通过多种方式解决,例如在每个输入单词后添加符号,或者将ε视为机器接受或拒绝的特殊情况。

1 From this definition of LBA it follows that the tape is completely empty when the input is the empty word ε, and then the machine cannot make any move. This technical problem can be solved in several ways, for example by adding the symbol after each input word or by treating ε as a special case that the machine has to accept or reject.

2在其他教科书中,您可能会遇到术语“多还原性” 。

2 In other textbooks you may encounter the termmany -one reducibility .

第6章

Chapter 6

1孪生素数是一对相差 2 的素数。

1 Twin primes are a pair of prime numbers that differ by 2.

2如果公式需要多个变量,可以使用符号w y zx 1 x 2 x 3等。我们不会将所有无限多个变量放入字母表中,因为字母表必须是有限的。相反,我们只有一个符号来表示变量x,然后我们可以使用x组成的字符串来表示其他变量,例如xx表示x 2 xxx表示x 3等等。

2 If a formula needs multiple variables, we can use the symbols w , y , z or x 1 , x 2 , x 3 and so on. We don't put all the infinitely many variables in the alphabet, because the alphabet has to be finite. Instead, we have just one symbol for the variable x , and then we can use strings of x to denote the other variables, for example xx for x 2 , xxx for x 3 and so on.

3模型也称为结构解释

3 A model is also called a structure or interpretation .

4在本章中,为了方便起见,我们改变了通常的N定义,使集合包含 0,即N = {0, 1, …}。

4 In this chapter, for convenience, we modify our usual definition of N so that it contains 0, i.e. N = {0, 1, …}.

5在一些研究中,描述性复杂性也称为Kolmogorov 复杂性Kolmogorov-Chaitin 复杂性

5 In some studies, descriptive complexity is also called Kolmogorov complexity or Kolmogorov–Chaitin complexity .

第7章

Chapter 7

1一些教科书使用名称“多项式多对一归约”

1 Some textbooks use the term many-to-one polynomial reduction .

2我们将在第 9.3 节中提出该定理的替代证明。

2 We present an alternative proof of this theorem in Section 9.3.

3我们可以使用转换函数在此处提供正确窗口的精确定义。然而,这非常耗时,并且会分散我们对证明主要流程的注意力。期望获得更高精确度的读者应该返回到定理 5.15 的证明分析,即关于邮政适用性问题的不可判定性。

3 We could give a precise definition of a valid window here, using a transition function. However, this is quite laborious and would distract us from the main flow of the proof. Readers who want more precision should return to the analysis of the proof of Theorem 5.15, concerning the undecidability of Post's correspondence problem.

第8章

Chapter 8

1稍后我们将证明萨维奇定理对于f ( n ) ≥ log n也成立。

1 We will show later that Savitch's theorem also holds for f ( n ) ≥ log n .

2当我们引入使用少于线性内存的图灵机时, f ( n ) ≥ n的要求稍后将推广到条件f ( n ) ≥ log n 。

2 The requirement that f ( n ) ≥ n will later generalize to the condition f ( n ) ≥ log n when we introduce Turing machines using less than linear memory.

第9章

Chapter 9

1回想一下,1 n表示由n个 1组成的单词。

1 Recall that 1 n means a word composed of n ones.

2回想一下, A B意味着 A 是B 的真子集(即A不等于B)。

2 Recall that A B means that A is a proper subset of B (i.e. A is not equal to B ).

3该证明中有一个地方需要进行一些技术讨论。在算法的第 4 步中, D为单词w模拟机器M。该模拟可能需要在机器D的磁带的几个单元中表示机器M的每个单元,因为机器 M 的磁带字母表是任意的,而机器 D 的磁带字母表是固定的。然而,通过将机器的输入字D转换为这种形式来启动模拟涉及重写w,使其符号分散在许多单元中。如果我们使用明显的复制例程来分散单词w,则此转换将花费O ( n 2 ) 时间,并且将超过小t的O ( t ( n )) 限制。

3 One place in the proof requires some technical detail. In step 4 of the algorithm, D simulates an M machine for a word w . This simulation may require representing each cell of M on several cells of the tape of D , since the tape alphabet of M is arbitrary and the tape alphabet of D is fixed. However, initiating the simulation by transforming the input D word into this form involves rewriting w so that its symbols are spread over many cells. If we use an obvious copy procedure to spread the word w , this conversion will take O ( n 2 ) time and will exceed the bound O ( t ( n )) for small t .

相反,我们可以注意到D对x 10 k形式的输入字进行操作,其中x = ‹ M,然后我们只需要处理大k的模拟。我们只考虑k > |x| 2 .我们可以通过首先使用明显的复制过程来分散w ,然后计算尾随零并使用此计数器重写它们。 x的传播时间为O ( |x| 2 ),即O ( n )。计算零的时间为O ( n log n ),即O ( t ( n )),因为函数t是时间可构造的。

Instead, we can see that D operates on input words of the form x 10 k , where x = ‹ M, and then we only need to handle simulation for large k . We only consider k > |x| 2 . We can scatter w by first using the obvious copy procedure, then counting trailing zeros and rewriting them using this counter. The time for scattering x is O ( |x| 2 ), which is O ( n ). The time for counting zeros is O ( n log n ), which is O ( t ( n )) , since the function t is constructible in time.

第9章

Chapter 9

1误差概率分析遵循切尔诺夫约束,这是概率论的一个众所周知的结果。我们在这里展示了另一种推理,其中我们将自己执行所有计算,而不管结果如何。

1 The analysis of error probability follows from the Chernoff bound , a well-known result of probability theory. Here we show an alternative reasoning in which we perform all the calculations ourselves, regardless of this result.

2如果有向图不包含环,则称为无环图。

2 A directed graph is called acyclic if it contains no cycles.

3i ≥ 2 时,使用对数存储传感器定义均匀性是 NC 类别i的标准,但当i = 1时给出不寻常的结果(其中包括作为标准 NC 类别1的子集)。我们坚持这个定义,因为它更简单并且足以满足我们的需求。

3 Defining uniformity by using a transducer operating on logarithmic memory is standard for NC classes and for i ≥ 2, but gives an unusual result for i = 1 (containing as a subset the standard NC class 1 ). We stick with this definition, as it is simpler and sufficient for our needs.

4 Steven Cook 将 NC 作为“Nick's class”的缩写而流行起来,因为 Nick Pippinger 是第一个理解其含义的人。

4 Steven Cook popularized the name NC as an abbreviation for "Nick's class" because Nick Pippinger was the first to understand its meaning.

5目前,DES 密码并不被认为是安全的。 21 世纪初,它的位置被高级加密标准 (AES) 取代 - 请注意。缺点。

5 Currently, the DES cipher is not considered secure. It was replaced in the early 21st century by the Advanced Encryption Standard (AES) – cons. note.